The code typically looks like this example, which resets a Yes/No field to No for all records: Function Unpick All() Dim db As DAO.
Database Dim str Sql As String str Sql = "UPDATE Table1 SET Is Picked = False WHERE Is Picked = True;" Set db = DBEngine(0)(0) db.
If you run that query directly from the Database Window or via Run SQL, the Expression Service (ES) in Access resolves those names and the query works.
The ES is not available in the Execute context, so the code gives an error about "parameters expected." It is possible to assign values to the parameters and execute the query, but it is just as easy to execute a string instead of a saved query.
Unfortunately if you want to run any code when this refreshes, there’s no native way to do this.
We can, however, create an event for this with a few short steps.
Instead of having a nice automatic ‘ticker’, we’re expected to click ‘Refresh’ to get the latest prices. They are data connections to external sources but do NOT appear as Excel Data Connections.
That means you can’t setup an automatic data refresh, as you would with normal data connections.
Action queries change your data: inserting, deleting, or updating records.
There are multiple ways to run the query through macros or code.
The class name is referred to in code later on in this post.
If you name it something different, be sure to adjust your code as well.
Paste the following code (updated on 10-Feb-14, thanks to Andy Pope for pointing out a flaw! Note that if you make changes to the class module you’ll have to run the initialize code again.