Results 1 to 3 of 3
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Clean up screen after Error Handler finishes.

    Access 2007 SqlServer 2008 using MZTools



    The development I am working on has lots of date fields. I am trying to develop a consistent process for the error handler when dates are entered. This is my first time trying to work on Error Handlers. When a person enters a date and mucks it up such as YYYY-M-DD the error handler fires and when it is finished I want it to clean up the date field on the form by clearing the offending data and placing the cursor at the start of the field. Here is my code. No matter what I do I cant get the code after the error message to work.I don't understand where the clean up code should go. Once I get this down I will apply it to all the date controls. Some of the error handling samples I have seen are really complex and long.

    Input Mask: 0000\-99\-99;;_

    Validation Rule: Is Null Or Not ALike "%[!0-9]%" And Len([AOBORFAsentDT])=8

    Validation Text: Date must be eight digits and entered YYYY-MM-DD.

    Control Tip Text: Enter Dates as YYYY-MM-DD

    Code:
     Private Sub AOBORFAsentDT_Click()
    
    On Error GoTo AOBORFAsentDT_Click_Error
    
    Me.AOBORFAsentDT.SelStart = 0
    
    On Error GoTo 0
    
    Exit Sub
    
    AOBORFAsentDT_Click_Error:
    
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure AOBORFAsentDT_Click of VBA Document Form_FrmPropYrFile"
    
    Resume AOBORFAsentDT_Click_Error
    
    Me.AOBORFAsentDT SetFocus
    
    Me.AOBORFAsentDT = Nothing
    
    Me.AOBORFAsentDT.SelStart = 0
    
    End Sub
    Thanks Phred

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I would also have an exit handler and resume to there:

    http://www.baldyweb.com/ErrorTrap.htm

    In any case, nothing after the Resume is going to run, because that line sends code elsewhere. Try putting it right after the message box.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    After reviewing your link here is what I have. It functions and displays the error message. But you have to close the message box and click in the field and the field cleans up and sets the focus. I think I have something wrong or out of place.

    Code:
    Private Sub AOBORFAsentDT_Click()
    
       On Error GoTo ErrorHandler
    
    Me.AOBORFAsentDT.SelStart = 0
    
       On Error GoTo 0
    
    ExitHandler:
    
    Me.AOBORFAsentDT = ""
    
    Me.AOBORFAsentDT.SelStart = 0
       
       Exit Sub
    
    ErrorHandler:
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure AOBORFAsentDT_Click of VBA Document Form_FrmPropYrFile"
    
    Resume ExitHandler
    
    End Sub
    Thanks Phred

Please reply to this thread with any new information or opinions.

Similar Threads

  1. error handler help
    By baronqueefington in forum Programming
    Replies: 3
    Last Post: 01-23-2015, 02:11 PM
  2. Need help with Error Handler
    By RingoStarr in forum Programming
    Replies: 5
    Last Post: 09-20-2013, 02:07 PM
  3. Simple Error Handler
    By Tim777 in forum Access
    Replies: 7
    Last Post: 11-16-2012, 06:23 PM
  4. Global Error Handler Issue
    By usmcgrunt in forum Programming
    Replies: 1
    Last Post: 11-02-2011, 08:26 PM
  5. Replies: 7
    Last Post: 12-13-2010, 03:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums