Query output filtered

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Query output filtered

Post by santosm »

Hi All,
I am trying to run a query here and have it output to a file on my network. The error that pops up is 3011 saying that it can't find the object "select * from..." I am sure i have something incorrect on the outputto command.

Code: Select all

strWhere = "IN (""AL"",""AK"",""AZ"")"
strLoc = "O:\CSDB\REPORTS\SalesReports\custbystate.xls"
sQuery = "select * from [qCustomerByState] where [STATE_24] " & strWhere
DoCmd.OutputTo acOutputQuery, sQuery, acFormatXLS, strLoc

Thanks,
Mark
Thanks,
Mark

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Query output filtered

Post by Rudi »

Try this:

Code: Select all

sQuery = "select * from [qCustomerByState] where [STATE_24] ='" & strWhere & "';"
or

Code: Select all

sQuery = "select * from [qCustomerByState] where [STATE_24] =" & Chr(34) & strWhere & Chr(34) & ";"
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Query output filtered

Post by Pat »

That won't work Rudi, because the WHERE clause has already got the IN condition, it doesn't need the = as well.

I would change the command:
strWhere = "IN (""AL"",""AK"",""AZ"")"
to:
strWhere = "IN ('AL','AK','AZ')"

In other word use ' instead of " in the IN condition.

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Query output filtered

Post by santosm »

Thanks again guys. I did get this working but the code was failing because of something in the query pointing to the SQL tables. Now that it is straightened out, it is all good.

Thanks,
Mark
Thanks,
Mark