Link to home
Start Free TrialLog in
Avatar of BDoubleU
BDoubleU

asked on

Run multiple queries from one command button

Can I code one command button to run multiple queries. IF so how?
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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
Private Sub Button_Click()
    DoCmd.OpenQuery Test1, acViewNormal
    DoCmd.OpenQuery Test2, acViewNormal
End Sub
Avatar of BDoubleU
BDoubleU

ASKER

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

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
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.
So then the first two posts should work for you..

Did you try them yet?
What was the result?
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.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you need further assistance on this question?
I feel like a moron. Sorry it took so long to close this question. Thanks for your help.
BDoubleU,

would you care to explain how your accepted suggestion resolve your problem of running multiple queries in the click of the command Button.