Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    18

    Unanswered: Disable Access default errors / Replace with msgbox

    I am have been trying to use a msgbox to validate two unbound date range textboxes. The problem is that when I enter invalid dates, an access error pops up when I try to leave the textbox. My msgbox and validation code are set to the click event of my filter button.

    After some google searching i have found a few things to change error messages to your own and have tried a few like this one: (2113 is the error I'm getting)
    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
        Case 2113
            On Error Resume Next
            Response = acDataErrContinue
            Case Else
                MsgBox "The form error, " & DataErr & " has occurred.", vbOKOnly, "Error"
                Response = acDataErrDisplay
        End Select
    
    End Sub
    I tried this a few different ways, but all it does is stop the error box from popping up, yet I cannot change focus to ANY other field or the button until I either enter a valid date or leave the field empty. I tried looking for another way to disable errors or warning in the settings but couldn't seem to find one. I also read about DoCmd.SetWarnings False but that did not seem to work either.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you have a user playing cute games with dates then I'd suggest you use a date picker control, supply a default value on start up and then you know you have a valid date.......
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2009
    Posts
    18
    I have the date picker enabled, but sometimes find it easier just to type in a date. If I could just replace the access error with my own to make it less generic and let the user know which date field is invalid that'd be great. The access error pops somewhere on the leave control event. I'm almost certain there is a way around it, as there are quite a few posts on the web about validating with msgboxes, though they never seem to mention the access error. Maybe this is something new in 2007 that can't be turned off?

    While writing this I just thought about something I've seen somewhere about GoTo 0 or something similar. Let me check that out and see what happens.
    Last edited by L3Tum; 03-25-09 at 16:42.

  4. #4
    Join Date
    Mar 2009
    Posts
    18
    Well I replaced the Case statements with if, and the msgbox is working. I then tried to comment out the msgbox line, and I get no error but again cannot move to another field. I guess I'll just leave the message box here on the textbox itself instead of on the filter button.
    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    
    If DataErr = 2113 Then
    Response = acDataErrContinue 
    MsgBox "Please enter a valid date in the following format: MM/DD/YYYY."
    Else
    MsgBox "Error#: " & DataErr
    Response = acDataErrDisplay 
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •