I am trying to run a set of queries using a command button so that it will delete the records from a table then append new records selected by queries. How I can do it? Is there any way?
north2060
I'm assuming that you have already created the appropriate Delete and Append queries you wish to run.
That being the case, you can run them all from code behind a command button...making sure that you run them in the proper order, so as not to leave orphaned records etc.
For example...
Dim stDocName As String
stDocName = "qryOne"
DoCmd.OpenQuery stDocName, acNormal, acEdit
stDocName = "Two"
DoCmd.OpenQuery stDocName, acNormal, acEdit
stDocName = "Three"
You may wish to put a line prior to running the first query to turn off warnings. Otherwise, you will get a warning message for each successive query.
DoCmd.SetWarnings False
After the last query, be sure to turn warnings back one again.
DoCmd.SetWarnings True
1. Create the delete and append queries and note the names and order in which they should be run.
2. Go to the Macro tab and create a new one.
3. Choose 'OpenQuery' in the option. At the bottom you will find a place to select from your queries. I always put the name in the description of the macro step so it is more visible. I also put 'Delete' and 'Append' in the query name so when you will open your macro all will be obvious. Do this for all of your queries.
4. Name your macro something obvious
5. Open your form in design view (or make a new one)
6. Choose View > Toolbox and drag the command button on your form.
7. The command buttom wizard will display.
8. Choose 'Miscellaneous' and 'Run Macro'and pick your macro.
That should do it .. for Access 97 anyway.
It's a good idea to get a good grasp of this before attempting to do these operations out of a module or behind a command button. Any decent Access text will describe these steps. If you have any problem with these steps you should check out the Microsoft Office forum.
Rusty
The early bird gets the worm, but the second mouse gets the cheese.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.