Table of contents
XML
TOC
Collapse the table of content
Expand the table of content

Perform Simple Data Validation Checks When Editing a Record in a Form

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

You can use the BeforeUpdate event of a form or a control to perform validation checks on data entered into a form or control. If the data in the form or control fails the validation check, you can set the BeforeUpdate event's Cancel argument to True to cancel the update.

The following example prevents the user from saving changes to the current record if the Unit Cost field does not contain a value.

Private Sub Form_BeforeUpdate(Cancel As Integer) 

   ' Check for a blank value in the Unit Cost field. 
    If IsNull(Me![Unit Cost]) Then 

       ' Alert the user. 
       MsgBox "You must supply a Unit Cost."   

      ' Cancel the update. 
      Cancel = True 
    End If 
End Sub
© 2018 Microsoft