I've created and save a query within Access and want to run it from within one of my modules. I have searched but can't find how to call it.
Can anyone help?
Printable View
I've created and save a query within Access and want to run it from within one of my modules. I have searched but can't find how to call it.
Can anyone help?
DoCmd.OpenQuery "your_queryname_here"
Salvelinus' method is one of many.
If you know the SQL then you can do just.. (This is the more efficient method)
VB Code:
CurrentDb.Execute "SQL String"
or you can pull the SQL from the query and then run it..
VB Code:
CurrentDb.Execute CurrentDb.QueryDefs("Query Name").SQL
As a note always use CurrentDb.Execute in favour of DoCmd.RunSQL, especially when performing action query's as this removes the need to suppress confirmation messages generated by the DoCmd.RunSQL method, and it is more efficient.