Solved

Access 2010 - using docmd.setwarnings False across various backends

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

762 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

19 Experts available now in Live!

Get 1:1 Help Now