Solved

multiple query submit in one button click MS Access VBA

Posted on 2014-01-15
6
1,803 Views
Last Modified: 2014-01-16
It is possible to run multiple queries and save those  results to multiple tables on a single button submit in MS Access form using vba right? I request to show if some experts know any examples as a demo.. Thanks
0
Comment
Question by:gtmathewDallas
  • 3
  • 3
6 Comments
 
LVL 34

Expert Comment

by:PatHartman
ID: 39783907
Sure.  First you need to create make-table queries.  To do that open the QBE and chose the first of your select queries.  Change the query type to Make-table and enter a table name.  Then do the same for each of the other queries.

With your form in design view, select your button.  press the builder button at the right edge of the Click Event box.  If given the choice, choose code.  You will be placed in a code module.
Enter one line of code for each query you want to run.  Change the query names to the ones you used when you saved the queries.

docmd.OpenQuery  "qMakeTable1"
docmd.OpenQuery "qMakeTable2"
docmd.OpenQuery "qMakeTable3"
....


When you run the code, you will get warning messages from Access telling you that you are making a table, blah, blah.  If you don't want to see them you can suppress them but don't forget to set them back on or you'll be sorry.


DoCmd.SetWarnings (False)

docmd.OpenQuery  "qMakeTable1"
docmd.OpenQuery "qMakeTable2"
docmd.OpenQuery "qMakeTable3"

DoCmd.SetWarnings (True)


Now comes the advice - you probably don't need to make all these extra tables plus they will bloat your database.  If you want the separate data for reporting or exports, simply use queries with selection criteria.  In Access, select queries are almost always interchangeable with tables so what you can do with a table, you can do with a select query without the bloat.
0
 

Author Comment

by:gtmathewDallas
ID: 39783982
Thanks for your valuable time, I am sorry may be my question was not clear but thanks for your reply... We have created tables..
My requirement is to save the history of a particular record (for example - room).
Some times the room functions - users or other related things can be change. But the management should be able to see the history of a that room based on a two date ranges, for example history of that room between 2011 January and 2013 January. Can you please advise me the best way to develop it?  I have now one table for room and another one for functions. Is it good to combine those tables to one table? Please help..
Thanks
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39784089
If you are creating history records each time something changes, you would use queries against your history table to produce reports for a point in time.  Usually, you don't archive data (create history tables) unless/until you end up with too much history that is no longer interesting but you still want to keep it.  Depending on the application, this might be anywhere from 1 month to 5 years.  Volume of data also impacts the decision regarding how long to keep history in the active tables.

Are you asking how to create the history records?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:gtmathewDallas
ID: 39784094
Yes Please Help
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39784110
First you need to decide which method is best.  This link will help with that -

http://www.4guysfromrolla.com/webtech/041807-1.shtml

Here's a link to one that is already built that you can add to your application.  It does require you to make changes to your code but is probably easier than building it yourself.

http://allenbrowne.com/AppAudit.html
0
 

Author Closing Comment

by:gtmathewDallas
ID: 39786169
Thank you So much.. :)
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now