1

I want to run a saved access query through a button click using VBA. I don't want the user to be asked to confirm that it runs.

CODE:

DoCmd.OpenQuery "QryAddTraining", acViewNormal, acAdd

This brings up the dialogue box "You are about to run append query that will modify data in your table" ....

I just want the VBA code to automatically select "Yes" and stop the user from seeing this interface.

1 Answer 1

1

Use DAO.Database.Execute to execute your query:

Dim db As DAO.Database
Set db = CurrentDb
db.Execute "QryAddTraining", dbFailOnError 

The dbFailOnError option is not required, but including it gives you better error information. Check the Access help topic for details.

Sign up to request clarification or add additional context in comments.

2 Comments

You can also use DoCmd.Setwarnings False, but I prefer the method suggested by @HansUp, as it allows you to identify other types of errors not shown when SetWarnings is turned off. (If you use SetWarnings, don't forget to turn it back on when you are done.)
A quick tip for writing shorter code: You can replace 3 lines with CurrentDB.Execute "QryAddTraining", dbFailOnError

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.