OpenQuery dynamic alternative?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is it possible to define a select query within VBA and then open it?

I would like to be able to define a select query dynamically from VBA
according to data that is held in another table.

Regards,
Ron.
 
Create an empty query, name it DynamicQuery, and try this code to assign new
SQL to this query, and then open the Query

Dim db As Dao.Database ,myqs As Dao.QueryDef

Set db = CurrentDb
Set myqs = db.QueryDefs("DynamicQuery")
myqs.sql = "SELECT * From TableName"
Docmd.OpenQuery "QueryName"
 

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

Back
Top