I have the following code on a subform, have tried putting it to different events, but can only get it to run the way I really want (not allowing you out of the begdate field until it's okay) unless I have it on the exit event. However, when I close the main form this code runs again (no matter where on the form or its many subforms I am on immediately before clicking the close button), and since the main form is closed it cannot find the dob it needs in the eighth line, so every time I close the main form I get an error. Is there code I can put in my closing routine to get this out of the way before I actually close the form?
Private Sub txtBegDate_Exit(Cancel As Integer)
Dim strmesg As String
If DateDiff("d", [BEG_DATE], Now()) < 0 Then
strmesg = "Start Date must be previous to today's date."
Cancel = True
TxtBegDate.setfocus
msgbox strmesg, vbOKOnly, "Invalid Start Date"
Exit Sub
End If
If Me.TxtBegDate < [Forms]![Frm_MainStu]![txtDOB] Then
If Me.TxtBegDate <> #1/1/45# Then
strmesg = "Start date must be later than student's date of birth. Please check."
Cancel = True
TxtBegDate.setfocus
msgbox strmesg, vbOKOnly, "Invalid Start Date"
End If
End If
End Sub
Private Sub txtBegDate_Exit(Cancel As Integer)
Dim strmesg As String
If DateDiff("d", [BEG_DATE], Now()) < 0 Then
strmesg = "Start Date must be previous to today's date."
Cancel = True
TxtBegDate.setfocus
msgbox strmesg, vbOKOnly, "Invalid Start Date"
Exit Sub
End If
If Me.TxtBegDate < [Forms]![Frm_MainStu]![txtDOB] Then
If Me.TxtBegDate <> #1/1/45# Then
strmesg = "Start date must be later than student's date of birth. Please check."
Cancel = True
TxtBegDate.setfocus
msgbox strmesg, vbOKOnly, "Invalid Start Date"
End If
End If
End Sub