Requiring data in one field based on another field's contents...

  • Thread starter Thread starter heidibb
  • Start date Start date
H

heidibb

Can you make one field required only if another field has data in it? For
example, if FirstName has data entered into it, the user would be required to
enter data in the LastName field. But, if there is no data in the FirstName
field then the LastName field would not be required.

This is a catalog request table, where they can go out to either individuals
or buildings, so I cannot make the FirstName and LastName field required in
the table. I was hoping to create a validation rule in the form and force it
during data entry to minimize the amount of incomplete records being entered.
 
heidibb,
you can use the before update event of the form to check this.

Private Sub Form_BeforeUpdate()
If Not IsNull(Me.FirstNameControlName) Then
If IsNull(Me.LastNameControlName) Then
Cancel = True
MsgBox "You must enter the Last Name"
End If
End If
End Sub

That code will prevent the user from saving the record and closing the form
if there is a first name but no last name.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
I take it, then, that you aren't planning any sales to Cher or
Prince...<g>?!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Back
Top