473,563 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine the state of SetWarnings?

MLH
I thought I could run docmd.SetWarnin gs in the
immediate window with no argument and A97
would return True or False, depending on the
current setting. I was wrong.

Anybody know how to make the determination
in the immediate window?
Mar 22 '06 #1
10 7196
On Tue, 21 Mar 2006 19:50:20 -0500, MLH wrote:
I thought I could run docmd.SetWarnin gs in the
immediate window with no argument and A97
would return True or False, depending on the
current setting. I was wrong.

Anybody know how to make the determination
in the immediate window?


I believe that this has been asked here before and it's not readable.

Perhaps you should search www.groups.google.com
Search for all of the words:

Check Status of SetWarnings
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Mar 22 '06 #2
On Tue, 21 Mar 2006 19:50:20 -0500, MLH <CR**@NorthStat e.net> wrote:

There is no way. If you have to know, carefully track it yourself.
It's OK to call DoCmd.SetWarnin gs multiple times with the same
argument.

-Tom.

I thought I could run docmd.SetWarnin gs in the
immediate window with no argument and A97
would return True or False, depending on the
current setting. I was wrong.

Anybody know how to make the determination
in the immediate window?


Mar 22 '06 #3
Fred and Tom are correct, so the question is how to proceed. The best
solution is not to mess with a setting you cannot determine.

Most often, we see people turn SetWarnings off so users do not get annoyed
with confirmation dialogs on action queries (insert, delete, or update.)
This is not a good approach. If the action query fails (records cannot be
added, removed, or altered), you get no warning, so your code is making
invalid assumptions about what it can do next.

A simple alternative is to use the Execute method instead of firing your
action query with RunSQL or OpenQuery. Example:
dbEngine(0)(0). Execute "Query1", dbFailOnError
That approach generates no confirmation message, so you do not need to mess
with SetWarnings. However, if the query fails to execute completely, it does
generate a trappable error, so your code does not blithely continue in
ignorance.

The disadvantage of the Execute method is that it does not call the
Expression Service. That means if Query1 contains a parameter such as:
[Forms].[Form1].[ClientID]
it will not work. One solution is to assign the parameter values, e.g.:
qdf.Parameters( "[Forms].[Form1].[ClientID]") =
[Forms].[Form1].[ClientID]
Personally, I find it easier to build a SQL string dynamically, e.g.:
strSql = "DELETE FROM Table1 WHERE ClientID = " & _
[Forms].[Form1].[ClientID] & ";"
dbEngine(0)(0). Execute strSql, dbFailOnError
This also has the advantage that your code is independent any saved query,
and makes the database easier to maintain.

If that is not enough to convince you to use Execute rather than RunSQL, the
Execute method also gives you the opportunity to create a transaction for an
all-or-nothing result. Details and example:
Archive: Move records to another table
at:
http://allenbrowne.com/ser-37.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthStat e.net> wrote in message
news:sn******** *************** *********@4ax.c om...
I thought I could run docmd.SetWarnin gs in the
immediate window with no argument and A97
would return True or False, depending on the
current setting. I was wrong.

Anybody know how to make the determination
in the immediate window?

Mar 22 '06 #4
MLH
Thanks to you all for very helpful
feedback. You guys are a great
asset to this NG.
Mar 23 '06 #5
DFS
MLH wrote:
Thanks to you all for very helpful
feedback. You guys are a great
asset to this NG.

MLH,

You can determine it and keep track of it at all times, by using a global
variable and a simple Sub proc.

Global glbWarningState as Boolean

Public Sub setWarningState (warnState as boolean)
DoCmd.SetWarnin gs warnState
glbWarningState = warnState
End Sub
In a routine that runs when the system is opened, set the global to True
(because the global var will be False by default, yet Warnings are On/True
by default):

Public Sub startupCode()
...
...
glbWarningState = True
End Sub

Afterwards, you only ever set Warnings on and off via the sub
setWarningState ():

if glbWarningState = True then
call setWarningState (False)
endif

Mar 23 '06 #6
MLH
Handy work-around.
Mar 23 '06 #7
On Thu, 23 Mar 2006 00:30:08 -0500, "DFS" <nospam@dfs_.co m> wrote:

Better yet: Make glbWarningState a function, so it can also be called
from a macro or directly from an event procedure property (both not
techniques I personally advocate).

-Tom.
MLH wrote:
Thanks to you all for very helpful
feedback. You guys are a great
asset to this NG.

MLH,

You can determine it and keep track of it at all times, by using a global
variable and a simple Sub proc.

Global glbWarningState as Boolean

Public Sub setWarningState (warnState as boolean)
DoCmd.SetWarnin gs warnState
glbWarningState = warnState
End Sub
In a routine that runs when the system is opened, set the global to True
(because the global var will be False by default, yet Warnings are On/True
by default):

Public Sub startupCode()
...
...
glbWarningState = True
End Sub

Afterwards, you only ever set Warnings on and off via the sub
setWarningStat e():

if glbWarningState = True then
call setWarningState (False)
endif


Mar 23 '06 #8
DFS wrote:
You can determine it and keep track of it at all times, by using a global
variable and a simple Sub proc.


Is this statement from MS-Access help wrong then?

"If the the warningson argument was set to False, the display of
warning messages automatically resumes when the code stops running."

Mar 23 '06 #9
On 23 Mar 2006 06:14:10 -0800, "Lyle Fairfield" <ly***********@ aim.com> wrote:
DFS wrote:
You can determine it and keep track of it at all times, by using a global
variable and a simple Sub proc.


Is this statement from MS-Access help wrong then?

"If the the warningson argument was set to False, the display of
warning messages automatically resumes when the code stops running."


Yes

Wayne Gillespie
Gosford NSW Australia
Mar 23 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1850
by: Bob | last post by:
In .NET, is there an easy way to determine State Holidays, such as Thanksgiving, Memorial day, etc? Any reference is appreciated.
13
12095
by: Robert McEuen | last post by:
This is probably really simple, but I can't find a thread that addresses it. Is there any way to evaluate in code whether the current state of the SetWarnings command is set to True or False? I have a Public Sub that I want to use from several areas of my application, and I want to turn off warnings for it, but I don't want to set warnings...
6
2270
by: MLH | last post by:
In my Tues, Mar 21 2006 original post on this topic, Allen Browne made a very good case for use of the Execute method instead of firing an action query with RunSQL or OpenQuery. Ex- ploring the topic just a bit further... I'm wondering if VB receives any event notice indicating that a confirmation dialog just opened? That is, can I tell...
5
1922
by: MLH | last post by:
Access 97 does not provide a means of reading the most recent setting for SetWarnings Method. For example, if you had CBF that called a procedure in a global module and the following statement was executed: DoCmd.SetWarnings False Then you would not be able to take peek at the setting when processing returned to the calling
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.