By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,954 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,954 IT Pros & Developers. It's quick & easy.

How to determine the state of SetWarnings?

P: n/a
MLH
I thought I could run docmd.SetWarnings 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
Share this Question
Share on Google+
10 Replies


P: n/a
On Tue, 21 Mar 2006 19:50:20 -0500, MLH wrote:
I thought I could run docmd.SetWarnings 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

P: n/a
On Tue, 21 Mar 2006 19:50:20 -0500, MLH <CR**@NorthState.net> wrote:

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

-Tom.

I thought I could run docmd.SetWarnings 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

P: n/a
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**@NorthState.net> wrote in message
news:sn********************************@4ax.com...
I thought I could run docmd.SetWarnings 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

P: n/a
MLH
Thanks to you all for very helpful
feedback. You guys are a great
asset to this NG.
Mar 23 '06 #5

P: n/a
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.SetWarnings 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

P: n/a
MLH
Handy work-around.
Mar 23 '06 #7

P: n/a
On Thu, 23 Mar 2006 00:30:08 -0500, "DFS" <nospam@dfs_.com> 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.SetWarnings 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 #8

P: n/a
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

P: n/a
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

P: n/a
rkc
Lyle Fairfield 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."


Did you find that while the Northwind.mdb file was open?

Mar 23 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.