?
Solved

Access 2010 - using docmd.setwarnings False across various backends

Posted on 2013-11-04
4
Medium Priority
?
927 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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