OpenQuery dynamic alternative?

R

Ron

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.
 
O

Ofer

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"
 
Top