Solved

Access 2010 - using docmd.setwarnings False across various backends

Posted on 2013-11-04
4
851 Views
Last Modified: 2013-11-17
My client has a separate backend database for each state - all with exactly the same design.

My .accdb frontend has functionality so users can open and close these state backends, with only one state 'open' at a time.   The code links to whichever state BE the user has chosen.

 In addition, the user can 'archive' data from the current state  BE into another empty BE.

The archive database is opened by:
Set ArchiveDB = DBEngine.OpenDatabase(Me.txtArchiveDB)

and the BE to delete archived records is currently linked backend.

My issue is with warnings.  I use docmd.setwarnings FALSE every time a new state BE is opened/linked and this works well.  But the user is getting warnings about updating  - I am guessing from the archive db.

So, how exactly does setting warnings off work where there are several backends, and how do I set warnings via VBA when I use the

Set ArchiveDB = DBEngine.OpenDatabase(Me.txtArchiveDB)

code?
0
Comment
Question by:MonkeyPie
  • 2
  • 2
4 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39621129
Instead of using DoCmd.RunSQL or DoCmd.OpenQuery for your action queries, use:

CurrentDB.Execute "DELETE * FROM YourTable WHERE ...", dbFailOnError

Open in new window

The CurrentDB.Execute syntax for UPDATE, DELETE etc action queries will avoid the warning messages you are describing, and the dbFailOnError will provide more meaningful error messages if there is something intrinsically wrong with the SQL statement itself.
0
 

Author Comment

by:MonkeyPie
ID: 39631634
Thank you mbizup, That is good info.  But I still want to know how setting warnings to off works when you are using several backends.  Does the warning flag apply to the front end regardless of what the 'confirm record changes option' is set for each individual backend?

Or, each time the user closes one state db and opens another (within the one session) does the warning setting get set to the current backend setting?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39641262
Hmm - I missed your reply here.

These MS articles explain what is at work here:
http://msdn.microsoft.com/en-us/library/office/ff837275.aspx  -- The Set Warnings Method
http://msdn.microsoft.com/en-us/library/office/aa223114(v=office.11).aspx -- The DoCmd Object

In a nutshell, from those articles and extending a little beyond:
1.  SetWarnings is a method of the DoCmd object
2.  The DoCmd object by default applies to the current database (ie: the Front End)
3.  The 'Parent' of the DoCmd object is the Application Object (if unspecified, this is understood as the current application)
4.  You can use Access Automation to open a separate instance of Access for another database, use Set Warnings to turn off the warnings for that application, and run your queries against that application.  Something like this (untested):

Dim db As Database
Dim objAcc As Access.Application

Dim strPath as string
strPath = "C:\YourFolder\YourDB.mdb"

Set objAcc = New Access.Application
Set db = objAcc.DBEngine.OpenDatabase(strPath)

objAcc.DoCmd.SetWarnings True
db.OpenQuery "YourUpdateQuery"
db.OpenQuery "YourInsertQuery"
db.OpenQuery "YourDeleteQuery"
objAcc.DoCmd.SetWarnings False

Set db = Nothing
objAcc.Quit
Set objAcc = Nothing

Open in new window


5. Or you can simply use CurrentDB.Execute YourSQLString, dbFailOnError instead :-)
0
 

Author Closing Comment

by:MonkeyPie
ID: 39654996
Thank you.

So that explains why my users get unexpected 'You are about to delete xx rows.' messages, even after I have turned OFF warnings.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now