473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to determine the state of SetWarnings?

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
10 7161
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
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
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
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.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
MLH
Handy work-around.
Mar 23 '06 #7
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
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
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...
6
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...
5
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.