Link to home
Start Free TrialLog in
Avatar of JudithARyan
JudithARyanFlag for United States of America

asked on

DoCmd.SetWarnings False is not working

I need to suppress the "you are about to delete 1 row(s)" error message.  I am using a MsgBox to verify which DELETE is being executed.  And I'm still getting the error message.  I've used this method before, why isn't it working now?  I'm using Access 2013.

If UserID = -1 Then
    DoCmd.SetWarnings False
    DoCmd.RunSQL ("DELETE * FROM SysUsers WHERE WSID = '" & GetWSID() & "'")
    MsgBox ("UserID = " & UserID)
    DoCmd.SetWarnings True

Judith
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I concur with Rey's comment. But your code as far as I can see should work. I remember a case where a user had a variable on his/her form called False. And that local variable took precedence over the global False.

Try rightclicking your the False variable, and select "Definition"
Avatar of JudithARyan

ASKER

I'm really concerned about having to change these SetWarning statements, since I have them throughout my app.  When I did a right click on False and selected Definition, I got the message that "Identifier under cursor is not recognized"  !!!!!

I'll have to do a Find throughout my app to see if I've used False inappropriately.  I don't think I have, but I need to check it.

Is there a way to turn off global variables like False in some other way?

Judith
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
create a copy of your db
in the copy, vba window hit CTRL  + F
in the Find What box, place  DoCmd.SetWarnings

select the Search Option Current Project

click Replace

in replace With box, place   'DoCmd.SetWarnings

click OK

that will comment all your DoCmd.SetWarnings

now go back to the codes you posted above and un-comment the two DoCmd.SetWarnings
test your code
"I'm really concerned about having to change these SetWarning statements,"
Like I suggested yesterday ... you should really get away from using the dangerous SetWarnings statements.
Setting warnings off is so dangerous that i created a macro to do it.  In the macro, I set the hourglass on and the warnings off.  The on macro sets the warnings on and the hourglass off.  This way I always have a visual clue when the warnings are off.  Replacing your set statements with the macro will be a smaller change than changing to use the .execute method but   I agree with Joe that the .execute is safer but creating the macro is easier to implement for old stuff.
Rey, I finally conceded and changed my SQL statements to Currentdb.Execute and I'm not getting errors.  Thanks for that!

Anders, If you hadn't mentioned going back in my code to see if the error was coming for something further back, I wouldn't have known which SQL statements to change!  Thanks to you too!

Experts Exchange is the best, what would I do without you guys!!!

Judith