Set Warnings Learning Experience

Steve R.

Retired
Local time
Today, 13:51
Joined
Jul 5, 2006
Messages
5,746
I have some text boxes that require that the user enter a date. If a mistake is made, ACCESS gives the useless message "that the value entered is not appropriate for the field." To get around this, I thought that using "DoCmd.SetWarnings False" in the textbox's before update event would work. That did NOT work.

What did work, is using the forms "OnError" event along with "Response = acDataErrContinue" See the sample code below.
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Dim ctlCurrentControl As Control
    Dim strControlName As String
    Dim intResponse As Integer
    Set ctlCurrentControl = Screen.ActiveControl
    strControlName = ctlCurrentControl.Name
    Select Case DataErr
        Case 2113
            MsgBox "You have entered an incorrect date; " & strControlName & Chr(13) & "The error code is: " & DataErr
            Response = acDataErrContinue
        Case Else
            MsgBox "An unknown error occured.  The error code is: " & DataErr
        End Select
End Sub
 
Watch out for setting warnings to false if you are not going to turn it back on immediately. You will end up deleting all kinds of things like forms and tables by accidentally pressing the delete key, and there will be no warning.

Evan
 
SetWarnings will not prevent an Error message which is what happens when incorrect data is entered
 
Thanks for the responses. I spent several hours experimenting with SetWanings and finding that it would not work. ACCESS help is basically useless for clarifying this shortcoming which is the purpose of this post, helping others see the shortcomings of SetWarnings.
 
These are two different things.

SetWarnings is a "Warning Message Dialog Box" where as Error Message is the "Error-Message Dialog Box".

SetWarnings Example.

DoCmd.RunSQL “Insert Into Table” will popup a Warning Message Dialog.

Thanks for the responses. I spent several hours experimenting with SetWanings and finding that it would not work. ACCESS help is basically useless for clarifying this shortcoming which is the purpose of this post, helping others see the shortcomings of SetWarnings.
 
Another way to think of it is that the SetWarnings takes care of those instances where confirmations of some sort are occuring and the use of the DoCmd.SetWarnings False is meant to allow Access to select the confirmation, in the affirmative, so as to eliminate the need for user input.

Error messages on the other hand are something different. They don't require user input to select Yes or No. So, the SetWarnings do not work for those since there is no user input expected.

Hopefully that helps a bit.
 
I'm not quite sure how Access help is useless in describing this:

SetWarnings Action

... However, error messages are always displayed. Also, Microsoft Access displays any dialog boxes that require input other than just choosing a button (such as OK, Cancel, Yes, or No)— for example, any dialog box that requires you to enter text or select one of several options.

Regardless, Bob is right in that SetWarnings kills the yes/no dialogs, but not error messages. So, it kills the "Are you sure you want to delete this table?" and "Are you sure you want to append 50,000 rows?" messages (and assumes "Yes"), but errors, dialogs that require a selections from multiple options, and the like can only be "controlled" automatically through code.
 

Users who are viewing this thread

Back
Top Bottom