Dynamically change Query SQL

  • Thread starter Thread starter Peter Hibbs
  • Start date Start date
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.
 
Try

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

The query need to be exist before running this code
 
Back
Top