Connecting Tech Pros Worldwide Help | Site Map

Check Status of SetWarnings

Robert McEuen
Guest
 
Posts: n/a
#1: Nov 13 '05
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.
PC Datasheet
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Check Status of SetWarnings


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
resource@pcdatasheet.com
www.pcdatasheet.com



"Robert McEuen" <UNSPAMrmceu1@yahoo.com> wrote in message
news:fbd4bbae.0406031006.1d76fb97@posting.google.c om...[color=blue]
> 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.[/color]


Salad
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Check Status of SetWarnings


Robert McEuen wrote:
[color=blue]
> 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.[/color]

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.

Allen Browne
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Check Status of SetWarnings


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" <UNSPAMrmceu1@yahoo.com> wrote in message
news:fbd4bbae.0406031006.1d76fb97@posting.google.c om...[color=blue]
> 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.[/color]


Doug Hutcheson
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Check Status of SetWarnings


"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
news:40bfd502$0$8110$5a62ac22@freenews.iinet.net.a u...[color=blue]
> It is good coding to return a state to the way you found it, but Access[/color]
does[color=blue]
> not let you read the state of SetWarnings.[/color]
<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[color=blue]
>[/color]


Allen Browne
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Check Status of SetWarnings


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" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au > wrote
in message
news:onRvc.44$EP1.2565@news.optus.net.au...[color=blue]
> "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
> news:40bfd502$0$8110$5a62ac22@freenews.iinet.net.a u...[color=green]
> > It is good coding to return a state to the way you found it, but Access[/color]
> does[color=green]
> > not let you read the state of SetWarnings.[/color]
> <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[/color]


Doug Hutcheson
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Check Status of SetWarnings


"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
news:40bfe650$0$8120$5a62ac22@freenews.iinet.net.a u...[color=blue]
> "Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au > wrote
> in message
> news:onRvc.44$EP1.2565@news.optus.net.au...[color=green]
> > "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
> > news:40bfd502$0$8110$5a62ac22@freenews.iinet.net.a u...[color=darkred]
> > > It is good coding to return a state to the way you found it, but[/color][/color][/color]
Access[color=blue][color=green]
> > does[color=darkred]
> > > not let you read the state of SetWarnings.[/color]
> > <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[/color]
>
>
> 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.
>[/color]

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


Salad
Guest
 
Posts: n/a
#8: Nov 13 '05

re: Check Status of SetWarnings


Doug Hutcheson wrote:[color=blue][color=green]
>>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.
>>[/color]
>
>
> 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-][/color]

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.


Ian Hinson
Guest
 
Posts: n/a
#9: Nov 13 '05

re: Check Status of SetWarnings


"Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au > wrote
in message news:_CSvc.51$EP1.2695@news.optus.net.au...
[color=blue]
> OK all you MVPs: what API needs to be called to read this value? It's[/color]
gotta[color=blue]
> be there somewhere in order to have effect![/color]

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.


Michael \(michka\) Kaplan [MS]
Guest
 
Posts: n/a
#10: Nov 13 '05

re: Check Status of SetWarnings


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" <pparagon@bigpond.net.au> wrote in message
news:0W8wc.6358$rz4.3076@news-server.bigpond.net.au...[color=blue]
> "Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au > wrote
> in message news:_CSvc.51$EP1.2695@news.optus.net.au...
>[color=green]
> > OK all you MVPs: what API needs to be called to read this value? It's[/color]
> gotta[color=green]
> > be there somewhere in order to have effect![/color]
>
> 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[/color]
SetWarnings[color=blue]
> = True such that no warnings are given.
>
> Ian Hinson.
>
>[/color]


Ian Hinson
Guest
 
Posts: n/a
#11: Nov 13 '05

re: Check Status of SetWarnings


"Michael (michka) Kaplan [MS]" <michkap@online.microsoft.com> wrote in
message news:40c1e482$1@news.microsoft.com...[color=blue]
> However, this will break any user who had that setting as being False
> already themselves?
>[/color]

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.
[color=blue]
>
> --
> 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" <pparagon@bigpond.net.au> wrote in message
> news:0W8wc.6358$rz4.3076@news-server.bigpond.net.au...[color=green]
> > "Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au >[/color][/color]
wrote[color=blue][color=green]
> > in message news:_CSvc.51$EP1.2695@news.optus.net.au...
> >[color=darkred]
> > > OK all you MVPs: what API needs to be called to read this value? It's[/color]
> > gotta[color=darkred]
> > > be there somewhere in order to have effect![/color]
> >
> > 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[/color]
> SetWarnings[color=green]
> > = True such that no warnings are given.
> >
> > Ian Hinson.
> >
> >[/color]
>
>[/color]


Michael \(michka\) Kaplan [MS]
Guest
 
Posts: n/a
#12: Nov 13 '05

re: Check Status of SetWarnings


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" <pparagon@bigpond.net.au> wrote in message
news:HAmwc.7347$rz4.6678@news-server.bigpond.net.au...[color=blue]
> "Michael (michka) Kaplan [MS]" <michkap@online.microsoft.com> wrote in
> message news:40c1e482$1@news.microsoft.com...[color=green]
> > However, this will break any user who had that setting as being False
> > already themselves?
> >[/color]
>
> In my example code I made a point of setting the option back to true[/color]
using:[color=blue]
> Application.SetOption "Confirm Action Queries", True
> immediately after running the query so as to restore the effect of[/color]
whatever[color=blue]
> 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"[/color]
whichever[color=blue]
> way you look at it.
>
> Ian.
>[color=green]
> >
> > --
> > 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" <pparagon@bigpond.net.au> wrote in message
> > news:0W8wc.6358$rz4.3076@news-server.bigpond.net.au...[color=darkred]
> > > "Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au >[/color][/color]
> wrote[color=green][color=darkred]
> > > in message news:_CSvc.51$EP1.2695@news.optus.net.au...
> > >
> > > > OK all you MVPs: what API needs to be called to read this value?[/color][/color][/color]
It's[color=blue][color=green][color=darkred]
> > > 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[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > True.
> > > Also, by setting the Option to False its overrides any previous[/color]
> > SetWarnings[color=darkred]
> > > = True such that no warnings are given.
> > >
> > > Ian Hinson.
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Ian Hinson
Guest
 
Posts: n/a
#13: Nov 13 '05

re: Check Status of SetWarnings


MichKa,
[color=blue]
> Did you read my post?[/color]
Yep.
[color=blue]
> What if their setting was False there?[/color]
Then SetWarnings has NO effect, and is ignored by Access.
(ie. No warnings are given, even if SetWarnings = On)
[color=blue]
> Your code will stomp on their setting.[/color]
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.
[color=blue]
> Which explains why SetWarnings is GOOD
> -- because you know if you set it --
> so you can unset it.[/color]

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.
[color=blue]
> Why muck with user settings when there is such an easy
> way to avoid it?[/color]

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.
[color=blue]
>
> --
> 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" <pparagon@bigpond.net.au> wrote in message
> news:HAmwc.7347$rz4.6678@news-server.bigpond.net.au...[color=green]
> > "Michael (michka) Kaplan [MS]" <michkap@online.microsoft.com> wrote in
> > message news:40c1e482$1@news.microsoft.com...[color=darkred]
> > > However, this will break any user who had that setting as being False
> > > already themselves?
> > >[/color]
> >
> > In my example code I made a point of setting the option back to true[/color]
> using:[color=green]
> > Application.SetOption "Confirm Action Queries", True
> > immediately after running the query so as to restore the effect of[/color]
> whatever[color=green]
> > 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[/color][/color]
by[color=blue][color=green]
> > leaving the Option in a False state, then it's already "game over"[/color]
> whichever[color=green]
> > way you look at it.
> >
> > Ian.
> >[color=darkred]
> > >
> > > --
> > > 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" <pparagon@bigpond.net.au> wrote in message
> > > news:0W8wc.6358$rz4.3076@news-server.bigpond.net.au...
> > > > "Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au >[/color]
> > wrote[color=darkred]
> > > > in message news:_CSvc.51$EP1.2695@news.optus.net.au...
> > > >
> > > > > OK all you MVPs: what API needs to be called to read this value?[/color][/color]
> It's[color=green][color=darkred]
> > > > 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[/color][/color]
> to[color=green][color=darkred]
> > > > True.
> > > > Also, by setting the Option to False its overrides any previous
> > > SetWarnings
> > > > = True such that no warnings are given.
> > > >
> > > > Ian Hinson.
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Michael \(michka\) Kaplan [MS]
Guest
 
Posts: n/a
#14: Nov 13 '05

re: Check Status of SetWarnings


"Ian Hinson" <pparagon@bigpond.net.au> wrote...
[color=blue]
> Good, apart from these limitations:
> 1) You can't read back what its current state is.[/color]

Which does not matter; like I said, you know if you set it.
[color=blue]
> 2) It is meaningless if the Confirm Action Queries option is False.[/color]

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>
[color=blue]
> (Not that I saw anyone offer this advice to the OP.)[/color]

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.


Closed Thread