Link to home
Start Free TrialLog in
Avatar of ShadowIT
ShadowITFlag for United States of America

asked on

Automatically Approve (Yes) Delete & Append Queries

Hello Experts,

I have a macro that is running several delete and append queries, but this still requires the user to click through all the "Yes" approval dialog boxes.  Is there a way to get these to approve automatically without a user's intervention?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Paul_Harris_Fusion
Paul_Harris_Fusion
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of Rey Obrero (Capricorn1)
Office button > options > client settings
Confirm section
uncheck Action queries
            record changes
Avatar of ShadowIT

ASKER

Capricorn1...I don't see client settings within Access Options.
I suggest you use the example posted by Paul as it is *much* safer than turning off warnings globally.

DBEngine(0)(0).Execute "Q1", dbFailOnError

Or

With CurrentDb
   .Execute "query1", dbFailOnError
   .Execute "query2", dbFailOnError
   .Execute "query3", dbFailOnError
 ' and so on
End With

and with the dbFailOnError option, errors that *you want to know about* will be raised, which you can trap with Error handling.

mx
SOLUTION
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
t is possible to globally turn off the security warnings but I would not do it. You will find it will get very easy to accidentally destroy your database. I have seen this happen to many people that go this route.

If you do decide to turn off the security warnings globally make sure that your database is spit and that you make lots and lots of backups.

that will only happen when the app is not designed properly...
SOLUTION
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
NOTE:  Be EXTREMELY careful with SetWarnings = False.  If you forget to execute a SetWarnings True ... and/or you code errors out ... leaving a False condition in effect ... you will run into a load of other undesirable issues ... such as ...

You open a form in Design view .... you make some changes ... you decide NOT to keep those changes ... you click the Close button ... expecting to see a WARNING message asking Do you want to ....
You WILL NOT see that message and the changes will be saved ... if a prior SetWarnings False is still in effect.  There are many other situations.

mx
All of these worked perfectly...thanks all!
DatabaseMX I tested that theory but it still does ask you if you want to save changes to a form even if SetWarnings is false  I believe SetWarnings only applies to queries.
I tested it and it does not for me ...
And I just double checked again (A2003)

In the vba Immediate Window, enter

docmd.SetWarnings false

Then open a Form in design view, move some control around ... and hit the red X button.  There is no prompt to Save Yes/No.

mx
Same thing with a query (or other object).  Open query in design view, add/delete/move something ... hit red X ... *no prompt*.  It automatically Saves ...

mx
test it in a macro window with just setwarnings false (in other words you forgot to put setwarnings true later on in the macro)
Well, why?
If you run code, and Set Warnings is not put back to True, you are hosed.

Did you try the test I showed.  It's been like this for years.  No theory, just fact.

mx
Yes I tried docmd.setwarnings in vba as you said and it works as you said, but just as "facty" is that I tested it in a macro before I posted and it doesn't stick after the macro completes.  Since the author of this question was using a macro to run their queries it takes a bit risk out I'd say.
Not in my mind. It's bad practice all the way around.  Bet hey ...

mx
Some people don't use VBA with Excel.  Using macros, what is your alternative?  Did you test the behavior I witnessed with a macro btw?