Turning off query prompts on runtime version of Access 2016

Andy Brown
Andy Brown used Ask the Experts™
on
Hi - For some reason, I cannot seem to switch off prompts to run existing Update/Delete queries (either stored queries or queries created on the fly).  I used to use something like this - but it no longer seems to work.

Application.SetOption "Confirm Action Queries", 0
Application.SetOption "Confirm Document Deletions", 0
Application.SetOption "Confirm Record Changes", 0

Any ideas?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Remote Training and Programming
Top Expert 2015
Commented:
Hi Andy,

rather than using DoCmd to execute a query, use
CurrentDb.Execute "MyQueryName"

Open in new window

Then you won't have to bother with the settings and it is better performance.

Instead of CurrentDb, you can use an object variable. For instance:
dim db as Dao.Database
set db = CurrentDb
db.Execute "MyQueryName1"
db.Execute "MyQueryName2"
set db = nothing

Open in new window

if a query you are running depends on the results of a previous query, before executing, refresh the tables and follow with DoEvents:
db.tabledefs.refresh
DoEvents

Open in new window

Andy BrownDeveloper

Author

Commented:
Thanks Crystal - I'm seeing a lot of suggestions to go that way (so I'm going to take a look at the code now).

Just out of curiosity - Do you know if they stopped providing those setup options, as I can't seem them anywhere now?

Anyhow, thanks again - very much appreciated.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
no points please.

Strongly agree with Crystal, better to use the Execute method than either:
docmd.RunSQL 

Open in new window

or:
docmd.OpenQuery

Open in new window

Personally, I like to add the dbFailOnError as an option so that I can record any errors that might occur and process them properly.
db.Execute "YourQueryName", dbFailOnError

Open in new window

But when you do this, you must have an error handler (you should anyway) to deal with any errors.
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
you're welcome, Andy

not being able to change the setup options may have something to do with permissions and where files are located. I have not done testing to know what might have changed.

dbFailOnError -- Dale brought this up and it needs consideration -- this is something that needs to be evaluated on a case-by-case basis.  For example, most of the append queries I run only add new records due to unique indexes not allowing duplicates to go in -- in those cases, I do want the rest of the records that are ok to go in, so I would not want the SQL to fail because some of the records didn't make it. (The Append query might be followed by an Update query to change the records that were already there).  To tell me if  the SQL itself has an error, I have code to run SQL statements that also returns how many records were changed.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
+1

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial