View Full Version : Using a field from form on Query


Accessme2
09-03-2004, 07:50 AM
Hi everyone,
I am having some problem with the syntax on my query, I am not sure how to do tell the query that when they enter the Rep to look for Rep* I want to look for anything on that field that have that word. When I do a query I just enter the rep initial like AWI* and I get anything that AWI have but when I use a the field that they enter on a form I don't knnow how to do it. This is my query:

SELECT Quotes.Quotenum, Quotes.Rep, Quotes.Location, Quotes.[Customer Name], Quotes.[Project Name], Quotes.State, Quotes.Amount, Quotes.Qty, Quotes.Type, Quotes.Status, Quotes.[Req'd], Quotes.Comments, Quotes.Comments1, Left([quotenum],4) AS Expr1
FROM Quotes
WHERE (((Quotes.Rep)=[Forms]![REP_FRM]![REP_IN]) AND ((Left([quotenum],4))=[Forms]![REP_FRM]![DATE_IN1]));

I am using Access 2000, any help would be appreciated.

Thanks

llkhoutx
09-05-2004, 10:06 AM
Your WHERE clause is incorrect, i.e.

WHERE (((Quotes.Rep)=[Forms]![REP_FRM]![REP_IN]) AND ((Left([quotenum],4))=[Forms]![REP_FRM]![DATE_IN1]));

The form references must be concantenated to the query string, as those values are variable. The method of cancentanation is different for numeric, string, & date values.

Numeric values are mereley concantenanted, i.e.

WHERE (((Quotes.Rep)=" & [Forms]![REP_FRM]![REP_IN] & ") AND ((Left([quotenum],4))=" & [Forms]![REP_FRM]![DATE_IN1] & "));"

String values are enclosed in quotation marks, i.e.

WHERE (((Quotes.Rep)=" & chr(34) & [Forms]![REP_FRM]![REP_IN] & chr(34) & ") AND ((Left([quotenum],4))=" & chr(34) & [Forms]![REP_FRM]![DATE_IN1]& chr(34) & "));"

Dates are enclosed in pound symbols, i.e.

WHERE (((Quotes.Rep)=#" & [Forms]![REP_FRM]![REP_IN] & "#) AND ((Left([quotenum],4))=#" & [Forms]![REP_FRM]![DATE_IN1] & "#));"

Jon K
09-05-2004, 04:52 PM
When I do a query I just enter the rep initial like AWI* ....

If what you mean is that when you enter AWI* in [Forms]![REP_FRM]![REP_IN], the query should return every [Rep] that begins with the three letters AWI, then you need to change the = sign to Like:-

WHERE (((Quotes.Rep) LIKE [Forms]![REP_FRM]![REP_IN]) AND ((Left([quotenum],4))=[Forms]![REP_FRM]![DATE_IN1]));


* is a wildcard character and needs the Like Operator.
.