Form Required Field

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.
 
A

Allen Browne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top