I am updating a data entry application for a case reading study. In the past, we have found that case reviewers, who do the data entry, sometimes skip certain fields, and we’d like to make those fields mandatory. The easiest way would be to make the fields required in the table, but that gives an incomprehensible error message. I tried making the validation for the text box and combo boxes that need to be filled in ,“Is not null” and adding a message to fill the box in, but that doesn’t seem to work: you can still save a record with the missing data, and no message shows.
I also tried code, which seems to work better.
There is one text box, txtSampleNo, and four combo boxes, cboECS, cboIndicated, cboIRT, and cboHighPriority,. I used this code:
The problem is that only the first "If" seems to work. If the txtSampleNo is empty, you get the message and can’t save the record until you've entered the data, but you can save the record and don't get a message if any of the four combo boxes are empty.
What have I done wrong?
Many thanks,
Henry
I also tried code, which seems to work better.
There is one text box, txtSampleNo, and four combo boxes, cboECS, cboIndicated, cboIRT, and cboHighPriority,. I used this code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtSampleNo) Then
MsgBox "Please enter a sample number "
Me.txtSampleNo.SetFocus
Cancel = True
End If
If IsNull(Me.cboECS) Then
MsgBox "Did this case originate with ECS? "
Me.cboECS.SetFocus
Cancel = True
End If
If IsNull(Me.cboIndicated) Then
MsgBox " Is this case indicated? "
Me.cboIndicated.SetFocus
Cancel = True
End If
If IsNull(Me.cboIRT) Then
MsgBox " Is this an IRT case? "
Me.cboIRT.SetFocus
Cancel = True
End If
If IsNull(Me.cboHighPriority) Then
MsgBox " Is this case High Priority? "
Me.cboHighPriority.SetFocus
Cancel = True
End If
End Sub
The problem is that only the first "If" seems to work. If the txtSampleNo is empty, you get the message and can’t save the record until you've entered the data, but you can save the record and don't get a message if any of the four combo boxes are empty.
What have I done wrong?
Many thanks,
Henry
Last edited by a moderator: