Solved

DoCmd.SetWarnings False is not working

Posted on 2016-11-02
9
38 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
  • 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 7

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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 7

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 35

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 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