Solved

DoCmd.SetWarnings False is not working

Posted on 2016-11-02
9
31 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 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
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 5

Expert Comment

by:Anders Ebro (Microsoft MVP)
Comment Utility
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
Comment Utility
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
 
LVL 5

Assisted Solution

by:Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP) earned 250 total points
Comment Utility
And you are sure that is the line generating the warning? Have you stepped through the code?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"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 34

Expert Comment

by:PatHartman
Comment Utility
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
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Like I said ....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now