Form Required Field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the best thing to use to make a field required on a form so that if
field is not filled and form can not close until field is completed? I would
prefer not to go to Table level.
 
The best approach is to set the Required property of the field in the table,
or at least set its Validation Rule in the table to Is Not Null. That way
the rule is enforced regardless of how the record is changed/added (e.g.
directly to the table, or via an action query).

If you want to do it through the form, use the BeforeUpdate event of the
form to test if the control IsNull(). This event fires even if the user
never visits the required control. Example:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Surname) Then
Cancel = True
MsgBox "You must enter a Surname."
Me.Surname.SetFocus
End If
End Sub
 
Back
Top