• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 722
  • Last Modified:

Run multiple queries from one command button

Can I code one command button to run multiple queries. IF so how?
0
BDoubleU
Asked:
BDoubleU
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Rey Obrero (Capricorn1)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
0
 
jppintoCommented:
Private Sub Button_Click()
    DoCmd.OpenQuery Test1, acViewNormal
    DoCmd.OpenQuery Test2, acViewNormal
End Sub
0
 
BDoubleUAuthor 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

0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
Jeffrey CoachmanCommented:
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
0
 
BDoubleUAuthor 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.
0
 
Jeffrey CoachmanCommented:
So then the first two posts should work for you..

Did you try them yet?
What was the result?
0
 
BDoubleUAuthor 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.
0
 
Jeffrey CoachmanCommented:

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
0
 
jppintoCommented:
Do you need further assistance on this question?
0
 
BDoubleUAuthor Commented:
I feel like a moron. Sorry it took so long to close this question. Thanks for your help.
0
 
Rey Obrero (Capricorn1)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.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now