Code for run two action query in one click without confirm any question. (1 Viewer)

Sokkheng

Member
Local time
Tomorrow, 00:36
Joined
Jul 12, 2023
Messages
34
In my database i have one blank table for store data that get from many query for share to other user use for make report or export to excell for what they want.
in my process :
1-I have one blank table
2-I create action query (delete query) for deleted previous data to make table clean prevent from duplicate data
3-I create action query (Append query) for add data from the query to the blank table
** I want to make command button with code that user can run those two queries in one click without confirm any question.
Thanks for any ideas.
Sokkheng
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:36
Joined
Oct 29, 2018
Messages
21,474
Look up the Execute method of the CurrentDb object.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:36
Joined
Feb 28, 2001
Messages
27,188
Darn, was distracted enough that theDBguy beat me to it. If you use CurrentDB.Execute of any action query you get no warning or confirm dialog, it just does it. Note that you still have a way to know if something went wrong. Look up the option dbFailOnError that goes with .Execute as a way to protect yourself if something goes awry.
 

GPGeorge

Grover Park George
Local time
Today, 10:36
Joined
Nov 25, 2004
Messages
1,873
As The_Doc_Man suggested, the more advantageous approach is CurrentDB.Execute, "YourQueryNameGoesHere", dbFailOnError.

That executes the query without warnings and, more importantly, without having to use extra code to turn off warnings and then turn them back on at the end. That's risky to the extent that an error can cause the code to exist the procedure leaving warnings in the disabled state, hiding any future errors from you. Not only that, hiding warnings also hides run time errors. Your code could fail to run the queries and you would not know it until you saw the bad data later. Silent, but potentially nasty problems.

Including the option to display an error message if the execute fails also ensures you are notified if the query fails, but only if it fails. That's what we want.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:36
Joined
Feb 19, 2002
Messages
43,275
That's risky to the extent that an error can cause the code to exist the procedure leaving warnings in the disabled state, hiding any future errors from you. Not only that, hiding warnings also hides run time errors. Your code could fail to run the queries and you would not know it until you saw the bad data later. Silent, but potentially nasty problems.
You can also lose design changes because if you forget to explicitly save first and close a form you've just spent an hour modifying, Access will silently DISCARD your changed - because it can't prompt you - and close the form without the changes.

This is sooooooooooooo dangerous that I created two macros - the only macros in my databases. One turns warnings off and turns the hourglass on and the second turns warnings on and turns the hourglass off.

By replacing the single commands with the macros, you always have the hourglass on when warnings are disabled. This is sufficiently annoying that you won't forget to turn them off if you were debugging and dropped out of the code before getting to the warnings on statement.

I'm not disagreeing with the suggestion to use the .execute method at all. I am only offering a safety play should you decide you want to stick with the current method.
 

Users who are viewing this thread

Top Bottom