Solved

DoCmd.SetWarnings False is not working

Posted on 2016-11-02
9
81 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
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.

 
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 38

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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