473,324 Members | 2,417 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,324 software developers and data experts.

Check Status of SetWarnings

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 back to True if the sub was invoked from another sub
or function where warnings had already been set to False.
Nov 13 '05 #1
13 11966
Your subs and functions that call the public sub should look like:

DoCmd.SetWarnings False
Call NameOfPublicSub
DoCmd.SetWarnings True

This code will branch to the public sub, execute it and then return to the line
below the Call statement. Therefore, Warnings will always be off when running
the public sub and then will be immediately turned back on when the public sub
is done.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

"Robert McEuen" <UN**********@yahoo.com> wrote in message
news:fb**************************@posting.google.c om...
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 back to True if the sub was invoked from another sub
or function where warnings had already been set to False.

Nov 13 '05 #2
Robert McEuen wrote:
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 back to True if the sub was invoked from another sub
or function where warnings had already been set to False.


Since it's not a property, more of a state performed by an action, I
doubt it. You might consider setting a global variable to track it.

Nov 13 '05 #3
It is good coding to return a state to the way you found it, but Access does
not let you read the state of SetWarnings.

Your options are to maintain your own flag, or to avoid using SetWarnings.

If you are running action queries, consider using the Execute method (DAO)
instead of RunSQL. Execute does not pop up the warnings, so there is no need
to toggle SetWarnings. It is also more powerful:
- the dbFailOnError switch lets you opt out if there is an error (such as a
concurrency issue that does not allow the action query to complete);
- you have the option to use a transaction around the whole process for an
all-or-nothing result;
- you can read the number of records affected.

Example:
Dim db As DAO.Database
Dim strSQL As String

Set db = dbEngine(0)(0)
strSQL = "INSERT INTO ...

db.Execute strSQL, dbFailOnError
MsgBox db.RecordsAffected " record(s) inserted."

Set db =Nothing

--
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.

"Robert McEuen" <UN**********@yahoo.com> wrote in message
news:fb**************************@posting.google.c om...
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 back to True if the sub was invoked from another sub
or function where warnings had already been set to False.

Nov 13 '05 #4
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
It is good coding to return a state to the way you found it, but Access does not let you read the state of SetWarnings. <snip>
Well, well.
I though it was available under GetOptions / SetOptions, but I must have
been mistaken.
Is there really no collection which can be traversed to find this value?
"8-\
Cheers,
Doug

--
Remove the blots from my address to reply

Nov 13 '05 #5
Let's know if you find one, Doug.

I gave up on SetWarnings in Access 2, for this very reason.

--
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.

"Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au > wrote
in message
news:on***************@news.optus.net.au...
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
It is good coding to return a state to the way you found it, but Access

does
not let you read the state of SetWarnings.

<snip>
Well, well.
I though it was available under GetOptions / SetOptions, but I must have
been mistaken.
Is there really no collection which can be traversed to find this value?
"8-\
Cheers,
Doug

Nov 13 '05 #6
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
"Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au > wrote
in message
news:on***************@news.optus.net.au...
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
It is good coding to return a state to the way you found it, but
Access does
not let you read the state of SetWarnings.

<snip>
Well, well.
I though it was available under GetOptions / SetOptions, but I must have
been mistaken.
Is there really no collection which can be traversed to find this value?
"8-\
Cheers,
Doug

Let's know if you find one, Doug.

I gave up on SetWarnings in Access 2, for this very reason.

--
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.


OK all you MVPs: what API needs to be called to read this value? It's gotta
be there somewhere in order to have effect!
<I never give up without a drink ... er ... fight ... >
"8-]

--
Remove the blots from my address to reply
Nov 13 '05 #7
Doug Hutcheson wrote:
Let's know if you find one, Doug.

I gave up on SetWarnings in Access 2, for this very reason.

--
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.

OK all you MVPs: what API needs to be called to read this value? It's gotta
be there somewhere in order to have effect!
<I never give up without a drink ... er ... fight ... >
"8-]


Just as you can "set warning False" in a form by simply entering
Response = acdataerrcontinue
in the forms' OnError event, I would think there is a flag somewhere
within access that gets set that when running a query or whatever tells
the system not to display a message. Instead of an API, I guessing the
flag gets set somewhere in a system table.
Nov 13 '05 #8
"Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au > wrote
in message news:_C***************@news.optus.net.au...
OK all you MVPs: what API needs to be called to read this value? It's gotta be there somewhere in order to have effect!


I'm not an MVP but ...
The OP can get around his problem by using:

Application.SetOption "Confirm Action Queries", False
DoCmd.RunSQL "UPDATE table1 (etc)"
Application.SetOption "Confirm Action Queries", True

This preserves the SetWarnings state for when the Option is set back to
True.
Also, by setting the Option to False its overrides any previous SetWarnings
= True such that no warnings are given.

Ian Hinson.
Nov 13 '05 #9
However, this will break any user who had that setting as being False
already themselves?
--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:0W*****************@news-server.bigpond.net.au...
"Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au > wrote
in message news:_C***************@news.optus.net.au...
OK all you MVPs: what API needs to be called to read this value? It's gotta
be there somewhere in order to have effect!


I'm not an MVP but ...
The OP can get around his problem by using:

Application.SetOption "Confirm Action Queries", False
DoCmd.RunSQL "UPDATE table1 (etc)"
Application.SetOption "Confirm Action Queries", True

This preserves the SetWarnings state for when the Option is set back to
True.
Also, by setting the Option to False its overrides any previous

SetWarnings = True such that no warnings are given.

Ian Hinson.

Nov 13 '05 #10
"Michael (michka) Kaplan [MS]" <mi*****@online.microsoft.com> wrote in
message news:40********@news.microsoft.com...
However, this will break any user who had that setting as being False
already themselves?

In my example code I made a point of setting the option back to true using:
Application.SetOption "Confirm Action Queries", True
immediately after running the query so as to restore the effect of whatever
the current SetWarnings setting may be, in line with the OP's original
question.

But if, as you suggest, some other programmer may abuse that principle by
leaving the Option in a False state, then it's already "game over" whichever
way you look at it.

Ian.

--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:0W*****************@news-server.bigpond.net.au...
"Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au > wrote in message news:_C***************@news.optus.net.au...
OK all you MVPs: what API needs to be called to read this value? It's

gotta
be there somewhere in order to have effect!


I'm not an MVP but ...
The OP can get around his problem by using:

Application.SetOption "Confirm Action Queries", False
DoCmd.RunSQL "UPDATE table1 (etc)"
Application.SetOption "Confirm Action Queries", True

This preserves the SetWarnings state for when the Option is set back to
True.
Also, by setting the Option to False its overrides any previous

SetWarnings
= True such that no warnings are given.

Ian Hinson.


Nov 13 '05 #11
Ian,

Did you read my post? What if their setting was False there? Your code will
stomp on their setting.

Which explains why SetWarnings is GOOD -- because you know if you set it --
so you can unset it. Why muck with user settings when there is such an easy
way to avoid it?
--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.

"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:HA*****************@news-server.bigpond.net.au...
"Michael (michka) Kaplan [MS]" <mi*****@online.microsoft.com> wrote in
message news:40********@news.microsoft.com...
However, this will break any user who had that setting as being False
already themselves?

In my example code I made a point of setting the option back to true

using: Application.SetOption "Confirm Action Queries", True
immediately after running the query so as to restore the effect of whatever the current SetWarnings setting may be, in line with the OP's original
question.

But if, as you suggest, some other programmer may abuse that principle by
leaving the Option in a False state, then it's already "game over" whichever way you look at it.

Ian.

--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:0W*****************@news-server.bigpond.net.au...
"Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au > wrote in message news:_C***************@news.optus.net.au...

> OK all you MVPs: what API needs to be called to read this value? It's gotta
> be there somewhere in order to have effect!

I'm not an MVP but ...
The OP can get around his problem by using:

Application.SetOption "Confirm Action Queries", False
DoCmd.RunSQL "UPDATE table1 (etc)"
Application.SetOption "Confirm Action Queries", True

This preserves the SetWarnings state for when the Option is set back to True.
Also, by setting the Option to False its overrides any previous

SetWarnings
= True such that no warnings are given.

Ian Hinson.



Nov 13 '05 #12
MichKa,
Did you read my post? Yep.
What if their setting was False there? Then SetWarnings has NO effect, and is ignored by Access.
(ie. No warnings are given, even if SetWarnings = On)
Your code will stomp on their setting. This could be easily overcome by calling GetOption first,
then restoring it to its original state afterwards (if that is any real
concern).
The OP wanted to retain the effect of SetWarnings which made me assume that
the option (Confirm Action Queries) was already in a True state in the first
place.
Which explains why SetWarnings is GOOD
-- because you know if you set it --
so you can unset it.
Good, apart from these limitations:
1) You can't read back what its current state is.
2) It is meaningless if the Confirm Action Queries option is False.
Why muck with user settings when there is such an easy
way to avoid it?
Well yes, the whole "problem" could have been avoided in the first place if
the OP had followed a simple rule:-
Always set SetWarnings to the required state immediately before running a
query, and never ASSUME it has been left is some state by some other
previous process.
(Not that I saw anyone offer this advice to the OP.)

Ian.

--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.

"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:HA*****************@news-server.bigpond.net.au...
"Michael (michka) Kaplan [MS]" <mi*****@online.microsoft.com> wrote in
message news:40********@news.microsoft.com...
However, this will break any user who had that setting as being False
already themselves?


In my example code I made a point of setting the option back to true

using:
Application.SetOption "Confirm Action Queries", True
immediately after running the query so as to restore the effect of

whatever
the current SetWarnings setting may be, in line with the OP's original
question.

But if, as you suggest, some other programmer may abuse that principle by
leaving the Option in a False state, then it's already "game over"

whichever
way you look at it.

Ian.

--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:0W*****************@news-server.bigpond.net.au...
> "Doug Hutcheson" <do*****************@nrm.blot.qld.blot.gov.blot.au >

wrote
> in message news:_C***************@news.optus.net.au...
>
> > OK all you MVPs: what API needs to be called to read this value?

It's > gotta
> > be there somewhere in order to have effect!
>
> I'm not an MVP but ...
> The OP can get around his problem by using:
>
> Application.SetOption "Confirm Action Queries", False
> DoCmd.RunSQL "UPDATE table1 (etc)"
> Application.SetOption "Confirm Action Queries", True
>
> This preserves the SetWarnings state for when the Option is set back to > True.
> Also, by setting the Option to False its overrides any previous
SetWarnings
> = True such that no warnings are given.
>
> Ian Hinson.
>
>



Nov 13 '05 #13
"Ian Hinson" <pp******@bigpond.net.au> wrote...
Good, apart from these limitations:
1) You can't read back what its current state is.
Which does not matter; like I said, you know if you set it.
2) It is meaningless if the Confirm Action Queries option is False.
Which also does not matter. Pretend it is called
"SetWarningsIfTheyAreSetElsewhere" and then you will know what it is doing.
Its not a bug, its behaving as expected.

<snip solution>
(Not that I saw anyone offer this advice to the OP.)


Actually, people did, in pointing out that it does not matter if it has been
set, etc.
--
MichKa [MS]
NLS Collation/Locale/Keyboard Development
Globalization Infrastructure and Font Technologies

This posting is provided "AS IS" with
no warranties, and confers no rights.
Nov 13 '05 #14

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

Similar topics

2
by: Craig M | last post by:
Hi, I have a form, frmInvoices and a subform, frmInvoicesSub. On the parent form, i have a "print report" button, that prints a report depending on an ID on the parent form. Each record in...
2
by: Cassie Pennington | last post by:
Is there a command to spell check fields in Access (probably in the afterupdate event)? Thanks in anticipation Cassie
1
by: Jim M | last post by:
To prevent data corruption I have replaced a memo field on my form with an unbound control on my form that I populate with a function that fills it from a memo field from my table. When the form is...
2
by: RLN | last post by:
Re: Access 2003 I have code to check to see if a table exists. There are several other tables (tblQ12, tblQ13, etc) that do already exist & this code runs fine; msgbox says the value returned is...
3
by: jsurkin | last post by:
I have a form that lists a single work request, with an attached continuous subform that lists specific items that are part of the request. Each item in the subform has a check box to indicate when...
10
by: Cliff72 | last post by:
Is there a way in VBA to check if a linked table in the database has been updated? Example: I have a table "LedgerTemp" which is a direct link to a text file on the LAN "Ledger.txt" This text...
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...
1
by: Lynx101 | last post by:
I've got the following code to work, but the problem is that it is check all fields on every record. Is there a way to make this work on one particular field AND only the current record? Dim...
5
by: Laetitia | last post by:
Hi All Please can anyone advise whether it is possible to display messages in the status bar. I have a number of update queries which will be run and need to find a way to identify which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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

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.