Error handling: Add new records (incomplete record / incorrect data)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robtyketto
    New Member
    • Nov 2006
    • 108

    Error handling: Add new records (incomplete record / incorrect data)

    Greetings,

    I added my error checking (see code below) on the Form "On Current" event as
    I believe this code will run upon any action on screen being actioned.

    Errors happen when users are adding incomplete/incorrect data then pressing
    the next navigation button which adds a record if it is the last record.

    Where is best to put my error validation?
    Thanks Rob


    Code:
    Private Sub Form_Current()
    
    On Error GoTo MyErr
    
    ExtenuatingCount = DCount("[StudentID]", "tblStudentsResultsDelivery", 
    "[StudentId]= '" & [txtStudentId] & "' AND [ExtenuatingCircumstances] = 
    True")
    
    If ExtenuatingCount > 0 Then
        Me.lblExtenuating.Visible = True
    Else
        Me.lblExtenuating.Visible = False
    End If
    
    MyExit:
      Exit Sub
    
    MyErr:
        MsgBox "Please check all information is correct and present", 
    vbExclamation
        Me.txtStudentId.SetFocus
    
    Resume MyExit
    
    End Sub
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, Rob.

    I guess under "error checking" you mean trapping faults (particulary index/constraint violation) when form saves a record into a linked table.
    If so, then use Form_Error event to handle the situation.

    Regards.
    Fish

    Comment

    • robtyketto
      New Member
      • Nov 2006
      • 108

      #3
      Cheers, thank for the advice.

      Will get researching that now !!

      Comment

      • robtyketto
        New Member
        • Nov 2006
        • 108

        #4
        I put some code in there, but when I try to add records where data is incomplete or junk I get error 2105 (cant move to next record).

        My error handling did nothing !

        I dont want to write code for every single item on the screen.

        Anyone offer any tips or advice?

        Copied code below, cheers Rob

        Code:
        Private Sub Form_Error(DataErr As Integer, Response As Integer)
        
        On Error GoTo MyErr
        
        MyExit:
          Exit Sub
         
        MyErr:
            MsgBox "Please check all information is correct and present", vbExclamation
            Me.txtStudentId.SetFocus
         
        Resume MyExit
        
        End Sub

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Originally posted by robtyketto
          I put some code in there, but when I try to add records where data is incomplete or junk I get error 2105 (cant move to next record).

          My error handling did nothing !

          I dont want to write code for every single item on the screen.

          Anyone offer any tips or advice?

          Copied code below, cheers Rob

          Code:
          Private Sub Form_Error(DataErr As Integer, Response As Integer)
          
          On Error GoTo MyErr
          
          MyExit:
            Exit Sub
           
          MyErr:
              MsgBox "Please check all information is correct and present", vbExclamation
              Me.txtStudentId.SetFocus
           
          Resume MyExit
          
          End Sub
          Ok.

          Lets clarify some things.
          • Once more. Do the changes you make in a record violate linked table rules (indexes, validation rules)?
          • Does the event handler ever run?
          • Do you use form navigation bar to move to a new record or you use custom buttons or whatever other involving VBA code? If so post the code.



          .....

          Oh, sorry. Didn't pay attention to the code. You just need to realize the difference between On Error statement which allows to handle errors raised by code and Form_Error handler which is fired when form fails to perform some action (e.g. save record). Your code should look like the following:
          Code:
          Private Sub Form_Error(DataErr As Integer, Response As Integer)
              MsgBox "Please check all information is correct and present", vbExclamation
              Me.txtStudentId.SetFocus
              Response = acDataErrContinue  'suppress Access error dialog 
          End Sub

          Comment

          Working...