Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetWarnings not Turning Warnings back on

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
I often have vba code that runs action queries and I want the warnings temporarily suppressed during their execution, so pretty much the standard usage for the SetWarnings method.
So at the beginning I put in:
DoCmd.SetWarnings (WarningsOff)
And at the end I put in
DoCmd.SetWarnings (WarningsOn)

Sometimes this seems to work, but most of the time the warnings stay off, which gives me problems. Does anyone know why this doesn't function? In fact, it might be that the only time it works right is if it's in a macro instead of code I find it suspicious that it doesn't automatically capitalize warningson and warningsoff, like the editor doesn't recognize them as special words.
 
There is no such constants as WarningsOn and WarningsOff. It is a parameter for you to pass TRUE or FALSE. The reason is works some of the time is that it is evaluating "warningsOff" to something other than -1 (true). It does not comeback on because "warningson" will resolve to something other than TRUE.
 
BTW google "option explicit". If you require variable declaration this would have not been a problem. When you tried to run the code it would have told you that "warningson" is an undeclared variable. In other words it thinks warningson is variant variable.
 
That makes sense. So I should just be able to put True or False, or 0 or -1 in there as the case may be. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top