Solved

DoCmd.SetWarnings False is not working

Posted on 2016-11-02
9
52 Views
Last Modified: 2016-11-03
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
0
Comment
Question by:JudithARyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 41870753
change this line

DoCmd.RunSQL ("DELETE * FROM SysUsers WHERE WSID = '" & GetWSID() & "'")

with

Currentdb.execute "DELETE * FROM SysUsers WHERE WSID = '" & GetWSID() & "'", dbfailonerror

and no need to use DoCmd.SetWarnings False, DoCmd.SetWarnings True
0
 
LVL 8

Expert Comment

by:Anders Ebro (Microsoft MVP)
ID: 41870783
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"
0
 

Author Comment

by:JudithARyan
ID: 41870812
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Assisted Solution

by:Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP) earned 250 total points
ID: 41870908
And you are sure that is the line generating the warning? Have you stepped through the code?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41870929
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
0
 
LVL 75
ID: 41870961
"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.
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 41871048
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.
0
 

Author Closing Comment

by:JudithARyan
ID: 41872587
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
0
 
LVL 75
ID: 41872621
Like I said ....
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question