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. 13 12007
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.
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.
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.
"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
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
"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
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.
"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.
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.
"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.
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.
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. > >
"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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |