Run a make table query from code

teknogeek9

Registered User.
Local time
Today, 11:09
Joined
Jan 4, 2001
Messages
15
I have a form that performs either a preview or print report. However, before the actual report can be executed (previewed or printed), I need to perform a make-table query. How do I go about coding the form so that the make-table query performs before the preview or print executes?
Thanks!
 
In the code for your print button before you print the report, put the following code in...

docmd.setwarnings false
docmd.openquery "QueryName"
docmd.setwarnings true

This code will turn off the system messages, run the query, and then turn the system messages back on. Hope this helps you.

Doug
 
Thanks Doug...it worked like a charm!
 
If you have your make table query built and you are opening the report with an event you can put this in your event procedure to first run the query and then open the report in preview mode.

DoCmd.OpenQuery "NameOfYourMakeTableQuery", acNormal, acEdit
DoCmd.OpenReport "NameOfYourReport", acPreview

If you don't have your make table query built yet. Run the query wizard, then go to design view and select Query from the File Menu. from there you will see several choices including Make Table. Select it and you will be presented with a text box for the name and location. Save the query and then use the code I posted above but put your new query name in there.

You may consider running a append query after the initial table is built or it will get written over. Also to stop the warnings that Access with throw at you for Appending/Overwriting you can set warnings to false before the code and then set them back to true after the code.

Post back if you have more questions.
 
I posted 17 minutes after the first post was made and it still wasn't fast enough!
 

Users who are viewing this thread

Back
Top Bottom