A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query with 2 parameters asks for 3



 
 
Thread Tools Display Modes
  #1  
Old March 21st, 2010, 10:00 AM posted to microsoft.public.access.queries
Avid Fan
external usenet poster
 
Posts: 30
Default Query with 2 parameters asks for 3

I want to search on first and last name at the same time, so I have made
a combined field called BigName. When I run this query I get a request
for three parameters not two. BigName comes up as a parameter.

Query1

PARAMETERS mBigName Text ( 15 ), mSuburb1 Text ( 15 );
SELECT Customer.ID, Customer.Title, Customer.First_Name,
Customer.Last_Name, Customer.Address1, Customer.Suburb1,
Customer.State1, Customer.Postcode1, Customer.Phone, Customer.Target,
Trim(Customer.First_Name)+' '+Trim(Customer.Last_Name) AS BigName
FROM Customer
WHERE (((Customer.Suburb1) LIKE LTrim(Trim([mSuburb1]))+'*') AND
(([BigName]) LIKE '*'+LTrim(Trim([mBigName]))+'*'))
ORDER BY Customer.Last_Name, Customer.Suburb1, Customer.Target;

Any help appreciated.

  #2  
Old March 21st, 2010, 12:47 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Query with 2 parameters asks for 3

Your problem is that you cannot refer to the calculated field by name in the
where clause. At the time the where clause is executed the calculated field
does not yet exist. You have to reiterate the calculation in the where clause.

PARAMETERS mBigName Text ( 15 ), mSuburb1 Text ( 15 );
SELECT Customer.ID, Customer.Title, Customer.First_Name, Customer.Last_Name,
Customer.Address1, Customer.Suburb1, Customer.State1, Customer.Postcode1,
Customer.Phone, Customer.Target
, Trim(Customer.First_Name)+' '+Trim(Customer.Last_Name) AS BigName
FROM Customer
WHERE (((Customer.Suburb1) LIKE LTrim(Trim([mSuburb1]))+'*')
AND ((Trim(Customer.First_Name)+' '+Trim(Customer.Last_Name)) LIKE
'*'+LTrim(Trim([mBigName]))+'*'))
ORDER BY Customer.Last_Name, Customer.Suburb1, Customer.Target;

I'm not sure why you are using all the TRIM commands. Especially since
LTRIM(TRIM(X)) will always give the same result as TRIM(X).

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Avid Fan wrote:
I want to search on first and last name at the same time, so I have made
a combined field called BigName. When I run this query I get a request
for three parameters not two. BigName comes up as a parameter.

Query1

PARAMETERS mBigName Text ( 15 ), mSuburb1 Text ( 15 );
SELECT Customer.ID, Customer.Title, Customer.First_Name,
Customer.Last_Name, Customer.Address1, Customer.Suburb1,
Customer.State1, Customer.Postcode1, Customer.Phone, Customer.Target,
Trim(Customer.First_Name)+' '+Trim(Customer.Last_Name) AS BigName
FROM Customer
WHERE (((Customer.Suburb1) LIKE LTrim(Trim([mSuburb1]))+'*') AND
(([BigName]) LIKE '*'+LTrim(Trim([mBigName]))+'*'))
ORDER BY Customer.Last_Name, Customer.Suburb1, Customer.Target;

Any help appreciated.

  #3  
Old March 21st, 2010, 01:37 PM posted to microsoft.public.access.queries
Avid Fan
external usenet poster
 
Posts: 30
Default Query with 2 parameters asks for 3

John Spencer wrote:
Your problem is that you cannot refer to the calculated field by name in
the where clause. At the time the where clause is executed the
calculated field does not yet exist. You have to reiterate the
calculation in the where clause.

PARAMETERS mBigName Text ( 15 ), mSuburb1 Text ( 15 );
SELECT Customer.ID, Customer.Title, Customer.First_Name,
Customer.Last_Name, Customer.Address1, Customer.Suburb1,
Customer.State1, Customer.Postcode1, Customer.Phone, Customer.Target
, Trim(Customer.First_Name)+' '+Trim(Customer.Last_Name) AS BigName
FROM Customer
WHERE (((Customer.Suburb1) LIKE LTrim(Trim([mSuburb1]))+'*')
AND ((Trim(Customer.First_Name)+' '+Trim(Customer.Last_Name)) LIKE
'*'+LTrim(Trim([mBigName]))+'*'))
ORDER BY Customer.Last_Name, Customer.Suburb1, Customer.Target;


Thank you very much!!!!!!


I'm not sure why you are using all the TRIM commands. Especially since
LTRIM(TRIM(X)) will always give the same result as TRIM(X).


In XBase and Visual Fox Pro Trim() only removes blank spaces to the
right of the text, LTrim to the left.

If you what to do both you use allTrim(). VB is different.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:23 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.