Results 1 to 4 of 4
  1. #1
    jimmyac23 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Posts
    5

    VBA Error Handling

    Hi, is there a way to turn off a specific error? The error in access is error #2105. I am telling my user to select a value if they did not already, and then setfocus back on the textbox, but I get an error message after I display the message box that "You can't go to the specified record" and would like to turn this message off. Thanks!



    Code:
    Option Compare Database
    
    Private Sub ContactType_AfterUpdate()
        ContactPosition.Requery
        ContactPosition.Value = ""
        Me.ContactType.SetFocus
    End Sub
    
        Private Sub Region_AfterUpdate()
        Borough.Requery
        Borough.Value = ""
        Neighborhood.Value = ""
        End Sub
    
    Private Sub Borough_AfterUpdate()
    Neighborhood.Requery
    Neighborhood.Value = ""
    End Sub
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
        'Contact Position
        If IsNull(Me.ContactPosition.Value) Or Me.ContactPosition.Value = "" Then
            MsgBox ("Please select a contact position.")
            Cancel = True
            Me.ContactPosition.SetFocus
        End If End Sub


  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,641
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jimmyac23 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Posts
    5
    Thanks! I tried adding in error handling into my code, but still was unsuccessful. I've been searching for a solution like this for many days now but am still very confused. Any help would be appreciated.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)    On Error GoTo ErrorHandler
        
        'Contact Position
        If IsNull(Me.ContactPosition.Value) Or Me.ContactPosition.Value = "" Then
            MsgBox ("Please select a contact position.")
            Cancel = True
            Me.ContactPosition.SetFocus
        End If
        
    MyExit:
        Exit Sub
    
    
    ErrorHandler:
        If Err.Number = 2105 Then Resume MyExit
            
        
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    The error may be coming from the form's error event rather than the before update event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. error handling
    By slimjen in forum Forms
    Replies: 6
    Last Post: 03-13-2013, 11:49 AM
  2. Error Handling Question - On Error Goto
    By redbull in forum Programming
    Replies: 7
    Last Post: 12-06-2012, 07:54 AM
  3. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  4. On Error handling
    By rivereridanus in forum Access
    Replies: 2
    Last Post: 06-18-2012, 07:46 AM
  5. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 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