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

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

Jeanette Cunningham

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
 
J

Jeff Boyce

I take it, then, that you aren't planning any sales to Cher or
Prince...<g>?!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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