DoCmd.OutputTo acOutputQuery help needed

GODZILLA

Registered User.
Local time
Yesterday, 20:20
Joined
Mar 15, 2010
Messages
70
Hello,

I have a little problem.

I want VBA to save a query as a csv file but rather than having a lot of individual queries i want the vba to express a little condition such as the one below. It is the where statement that i need help with.

DoCmd.OutputTo acOutputQuery, "qry_nb" where [Agency_Code] = 1, (snipit not full code)

This does not work anyideas on how i would do this?

Thanks
 
The correct Syntax for OutputTo is:

OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)

so you should follow this:
your code: DoCmd.OutputTo acOutputQuery, "qry_nb" where [Agency_Code] = 1, is wrong. use Where clause in your query instead.
so you will get the result of where [Agency_Code] = 1 in your query, after you get your result then just use DoCmd.OutputTo acOutputQuery, "qry_nb" without WHERE clause
 
Here's an idea:

Dim db As dao.Database, qdf As QueryDef, strWHERE As String, mySQL As String

Set db = CurrentDb
Set qdf = db.QueryDefs("Query1")

Const strSQL = "SELECT * FROM Table1 "

qdf.SQL = strSQL & "WHERE ....;"

Set qdf = Nothing
Set db = Nothing

docmd.OutputTo acOutputQuery, "Query1" ....
 
The correct Syntax for OutputTo is:

OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)

so you should follow this:
your code: DoCmd.OutputTo acOutputQuery, "qry_nb" where [Agency_Code] = 1, is wrong. use Where clause in your query instead.
so you will get the result of where [Agency_Code] = 1 in your query, after you get your result then just use DoCmd.OutputTo acOutputQuery, "qry_nb" without WHERE clause

Using this idea i will have to set up a lot of queries, this is why i am trying to use code instead.

Thanks
 
Using this idea i will have to set up a lot of queries, this is why i am trying to use code instead.

Thanks

if you have already created "qry_nb", then just set the where clause in your query.
can you Post the SELECT statement of your query?? we will fix it.
 

Users who are viewing this thread

Back
Top Bottom