We help IT Professionals succeed at work.

Run multiple queries from one command button

BDoubleU
BDoubleU asked
on
Medium Priority
1,368 Views
Last Modified: 2013-11-28
Can I code one command button to run multiple queries. IF so how?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
private sub btn_click()

docmd.openquery "Q1"

docmd.openquery "Q2"

end sub

this  will depend on what kind of query you are going to run

Commented:
Private Sub Button_Click()
    DoCmd.OpenQuery Test1, acViewNormal
    DoCmd.OpenQuery Test2, acViewNormal
End Sub

Author

Commented:
I want the person who is going to maintain this database to be able to run all the needed queries to make the database functional. The problem is that I'm importing data from a .csv file. But the fields when imported need to be a mix of dates and currency. Plus, some of the Prices are final while others are added together. Here are the queries I need to run in order:

An append query
An append query
An inner join (in the form of a select query)
A Join Tables query
An Append query
An append query
An inner join (in the form of a select query)
An append query
An append query
An append query

Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
BDoubleU,

Are all of these queries separate unique queries, saved and listed in the database window?
If so, then both of the above posts will do this for you, just substitute you own query names.

If you are saying that you need to "Join" certain tables and create brand new queries "on-the-fly", (that may contan different object names), then this will be another thing entirely.

Please carify what each of these "Join" queries will actually be doing please.

Thanks
;-)

JeffCoachman

Author

Commented:
One of the join queries is used to combine a table with months and periods.

I have a table that has the following data (example):
Price Date             Curve Name        Month           Expected Price
1/31/2008              NGX AECO        JAN-2009        7.95

This is how the data comes over from the daily excel spreadsheets. But the end user wants another field added to make sorting easier. That field is called peak period. So I created a table with each month from now to 2050 and what period it is. June, for instance is "No" (as in not a peak period). JAN-2009 is part of "Winter-2008".

The other join query is similar.

Each query is a stand alone query. There is no data entry required by users to run the queries as they are designed only to take the imported data--which is in an Excel Spreadsheet in .csv format--and make it useful and readable. Each of the above queries is designed to make put the data in its final form. Again, no data entry is required to run the queries.
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
So then the first two posts should work for you..

Did you try them yet?
What was the result?

Author

Commented:
This did work but I had to remove the two innerjoin queries from the commands. They run themselves when the two queries that succeed them are ran.

The one question I have is if I can change to commands to run the queries and not open them. I don't want the person responsible for maintaining this database to have to click the "Yes" 20 times. Each query leads to two pop-ups and the whole point of this was for a one button click way to run all these queries.
MIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012
Commented:

To turn off the SQL Alerts use this:
    Docmd.Setwarnings=False

Obviously use this to turn them back on when you are done.
    Docmd.Setwarnings=true

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Do you need further assistance on this question?

Author

Commented:
I feel like a moron. Sorry it took so long to close this question. Thanks for your help.
CERTIFIED EXPERT
Top Expert 2016

Commented:
BDoubleU,

would you care to explain how your accepted suggestion resolve your problem of running multiple queries in the click of the command Button.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.