Solved

Access 2010 - using docmd.setwarnings False across various backends

Posted on 2013-11-04
4
863 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

785 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