Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Required Conditional Fields

Status
Not open for further replies.

jabrony76

Technical User
Apr 23, 2001
125
US
Hi all,
I would like to know if its possible to make a field required in a form based on previous entries for that record. For Example, if someone enteres in an admission date, the discharge date becomes required but if admission is null then discharge date is not required. I'm using Access 97 at work and 2000 at home and I don't know much about writing code so please be gentle.

thanks a bunch!
Andy
 
One way is to do a check on the field in the form's Before Update event. The code could look like...

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(AdmitDt) = False And IsNull (DischDt) = True Then
Msgbox "Please enter Disch date when Admit date exist."
Docmd.CancelEvent
DischDate.SetFocus
Exit Sub
End If

Hope this helps.
ljprodev@yahoo.com
ProDev, MS Access Applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top