Results 1 to 6 of 6
  1. #1
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194

    Error Handling... Totally not getting this right (handled, but still showing default error)

    Hey all,

    I have a subform in my main form which has 2 required properties.

    If the subform record is created and the required are not filled in, and the user tries to leave the subform then i get "error the, ClaimtypeID is null" etc etc.

    So i ran an error checker for msgbox dataerr and it throws up 3314.


    So i added

    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    
    MsgBox DataErr
    Select Case DataErr
    Case 3314
    
    
    MsgBox "You need to enter all required information before leaving the Claim Section"
    On Error Resume Next
    
    
    Case Else
    MsgBox "another error" & DataErr
    On Error Resume Next
    End Select
    
    
    
    
    End Sub
    Into the Subform Form_error event.

    My message comes up correctly "you need to enter all required...etc etc" and i used F9 to see where the code was running and it did go to on error resume next, then it pops up with the default message of the same error i just handled!

    I believe that means that this error is being generated from somewhere else but i CANT find where!!

    The original error is being triggered by trying to leave the subform without filling required fields, but how do i find WHERE the second error is being generated if my error handler (above) only gives me the 3314 answer!?

    I need to add handlers into all my procedures which i havent done before and I know it is 100% the thing to do so I'm trying to learn the theory but getting a bit confused!

    THanks for any help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Even though you have tried to 'trap' the error, you haven't aborted saving the record. So Access still hits the required fields and there is no data so the error message pops up.

    Usually, data validation is handled in BeforeUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194
    thanks June, so doing "before update" for the whole Subform.Form Event??

    I don't want it asking the question just because someone skips past a field because they may go back to it before exiting the subform.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yes, form BeforeUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194
    k thanks June7

    I now have these:

    and still getting the same error but i cant figure where to catch it.

    As a side note, it occurs when leaving the "required field" after an update,

    however i have nothing in the events for this field

    So it must be running off the form_update event, but it isnt getting caught?

    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    
    
    
    Select Case DataErr
    Case 3314
    
    
    MsgBox "This is from Form Error"
    On Error Resume Next
    
    
    Case Else
    MsgBox "another error" & DataErr
    On Error Resume Next
    End Select
    
    
    
    
    End Sub
    
    
    Private Sub Form_BeforeUpdate(cancel As Integer)
    Dim DataErr As Integer
    Dim Response As Integer
    
    
    Select Case DataErr
    Case 3314
    
    
    MsgBox "This Is from Form Before Update"
    On Error Resume Next
    
    
    Case Else
    On Error Resume Next
    End Select
    End Sub

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It triggers because you have the field set as required in the table.

    In the BeforeUpdate event, need to invoke: Cancel = True

    Review https://msdn.microsoft.com/en-us/lib...or=-2147217396
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Error handling of table update error?
    By panoss in forum Forms
    Replies: 5
    Last Post: 10-31-2014, 02:06 PM
  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