Results 1 to 6 of 6
  1. #1
    panoss is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Oct 2014
    Posts
    59

    Error handling of table update error?

    I have a table which has a field with 'Requiered=Yes'.
    A form is based on this table.
    When I open the form (in form view) and edit a record, I leave this field empty. Null.
    When I click on another field in the form, a message pops up showing the error:
    Cannot update because the field is Required and cannot contain null value.
    (everything as expected)

    How can I do error handling?
    The 'On Error' event of the form is not raised, the error does not happen in the "Before update' of the control...


    I have put code to show me message if the error happens, in:
    The control's before update.
    In the form's before update.
    In the Form_Dirty.
    In the form Error event.
    Nothing, the only error is raised from the application:
    Click image for larger version. 

Name:	error.jpg 
Views:	6 
Size:	13.7 KB 
ID:	18549

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In the table (and maybe the form) the field has a property:
    VALIDATION RULE
    or
    ALLOW ZERO LENGHT = NO

    change the design if needed,
    or dont let the field be null

  3. #3
    panoss is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Oct 2014
    Posts
    59
    'Allow zero length' only applies to fields of 'text type'.
    Mine is a number field.

    Is there any way, in the table, when it's null to automatically become 0?
    I tried with Nz function, but didn't achieve anything.

  4. #4
    panoss is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Oct 2014
    Posts
    59
    I set the field's required to false. So the error is gone.

    I want on the 'before update' event of the field in the form, to check if it's null, and if it is then make it equal to 0.
    But this can't set the field's value in the before update event of the field. It raises an error.
    Should I use the field's 'lost focus' maybe? It doesn't sound too elegant...

  5. #5
    panoss is offline Advanced Beginner
    Windows 2K Access 2003
    Join Date
    Oct 2014
    Posts
    59
    I set the field's (and the respective control's in the form) default value to 0.
    I used the AfterUpdate event of the field.
    Code:
    Private Sub GetesPieces_AfterUpdate()
        If IsNull(Me.GetesPieces) Then
            Me.GetesPieces = Me.GetesPieces.DefaultValue
        End If
    End Sub
    It works fine (before update of the field, if null, makes it 0) though I don't know if that's the 'neatest' way to do this.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    GetesPieces_AfterUpdate is not going to fire unless data is physically entered into the GetesPieces Control! If you set Zero as the Default Value, you need do nothing else! If no other value is entered, the Control, when the Record is saved, will be Zero!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  5. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM

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