I have a tabbed form. Tab 1 has fields that are mandatory. I am trying
to validate that these fields are not null, and cancel updating if any
of them are. The following code works, except the form closes instead
of setting focus to the null field. What am I doing wrong? Do I need to
refer to the tab name when I set focus? I sure would appreciate any
help!
Here is my code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.TherapyStartDate & "") = 0 Then
Cancel = True
MsgBox "You must enter a value in Date!"
Me!TherapyStartDate.SetFocus
ElseIf Len(Me.TherapyStartTime & "") = 0 Then
Cancel = True
MsgBox "You must enter a value in Start Time!"
Me!TherapyStartTime.SetFocus
ElseIf Len(Me.TherapyEndTime & "") = 0 Then
Cancel = True
MsgBox "You must enter a value in End Time!"
Me!TherapyEndTime.SetFocus
End If
End Sub