I have a form with a test list. Each test is a record with a yes/no checkbox, and controls for testdate and examiner. I don't want the user to be able to exit a record if the yes box is checked and either the testdate or examiner fields are blank. The code I am using is:
If IsNull(Me.Examiner) And Me.SelectTest = Yes Or IsNull(Me.TestDate) And Me.SelectTest = Yes Then
MsgBox "You must enter an examiner and a test date for each test you select.", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me.Examiner.SetFocus
Cancel = True
Else
Cancel = False
End If
I am having trouble with which event should be used with the code, however. In both before and after update I have had the following problem. If a user accidentally checks the wrong test and then unchecks it, they still get the message as if the box were still checked yes. Can anyone tell me why and how to avoid that?
Thanks in advance,
Carly
If IsNull(Me.Examiner) And Me.SelectTest = Yes Or IsNull(Me.TestDate) And Me.SelectTest = Yes Then
MsgBox "You must enter an examiner and a test date for each test you select.", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Me.Examiner.SetFocus
Cancel = True
Else
Cancel = False
End If
I am having trouble with which event should be used with the code, however. In both before and after update I have had the following problem. If a user accidentally checks the wrong test and then unchecks it, they still get the message as if the box were still checked yes. Can anyone tell me why and how to avoid that?
Thanks in advance,
Carly