MS Access - execute a saved query by name in VBA

tdjfdjdj picture tdjfdjdj · Mar 29, 2012 · Viewed 132.9k times · Source

How do I execute a saved query in MS Access 2007 in VBA?

I do not want to copy and paste the SQL into VBA. I rather just execute the name of the query.

This doesn't work ... VBA can't find the query.

CurrentDb.Execute queryname

Answer

Taryn picture Taryn · Mar 29, 2012

You can do it the following way:

DoCmd.OpenQuery "yourQueryName", acViewNormal, acEdit

OR

CurrentDb.OpenRecordset("yourQueryName")