Mandatory Fields in Forms??

  • Thread starter Thread starter Al Gavenas
  • Start date Start date
A

Al Gavenas

We have database which uses several forms for data entry,
and feeds a table.Each form has unique data that is
required. My question: Is it possible to make a data field
in a form mandatory information? Our forms are set up to
screen the data before allowing the information to be
entered in the table. Unfortunately if our data entry
clerk tabs over a particular field, no data is entered and
the information never entered or screened. Is it possible
to make a data field in a particular form mandatory
information? I know it can be done in the table, but we
are trying to use the form for this screening process.
 
Do you have a brief example of how I could set this up?
Sounds like this would work for me!!

Thanks Al
 
Is it possible
to make a data field in a particular form mandatory
information? I know it can be done in the table, but we
are trying to use the form for this screening process.

You'll need a little bit of VBA code to do this. Open the Form in
design mode and view its Properties; on the Events tab select the
BeforeUpdate event and click the ... icon. Choose the Code Builder
option; Access will give you the Sub and End Sub lines. Edit to
something like:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If IsNull(Me!txtMyTextbox) Then
MsgBox "Please fill in MyTextbox before saving", vbOKOnly
Me!txtMyTextbox.SetFocus
Cancel = True
End If
End Sub

This will prompt the user, put the cursor into the textbox, and cancel
actually saving the record until they enter something.
 
Back
Top