Dynamically change Query SQL

P

Peter Hibbs

Hi All

A2000

How can I change the SQL definition of an existing Query using VBA
code.

What I am trying to do is export data from a table as a .csv file
using the TransferText command. The problem is that the number of
fields, the field names and the data (of course) are not known at
Design time, it all depends on what the user chooses.

My idea is to create a query in VBA code, copy the SQL string to the
Query and then run theTransferText command with the Select Query as
the 'tablename' parameter.

Is this possible and how?

Peter Hibbs.
 
G

Guest

Try

CurrentDb.QueryDefs("QueryName").SQL="Select Field1, Field2 From TableName"

The query need to be exist before running this code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top