Solved

Access 2010 - using docmd.setwarnings False across various backends

Posted on 2013-11-04
4
911 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

729 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