Hello,
I am new to VBA. Could you, please, tell me what's wrong with the code
Validation rule for some reason does not start working until I enter something in the field and then delete it to make it Null. That's why I added LostFocus event. When I am loosing focus from the field, I get the intended message, however the SetFocus command does not work.
Thank you.
Regards,
Irene
I am new to VBA. Could you, please, tell me what's wrong with the code
Code:
Private Sub HOSPITAL_Change()
If HOSPITAL.Value <> "Other" Then
OTHHOSP_label.Visible = False
Me.OTHHOSP.Visible = False
Me.OTHHOSP.Value = Null
End If
If HOSPITAL.Value = "Other" Then
OTHHOSP_label.Visible = True
Me.OTHHOSP.Visible = True
Me.OTHHOSP.SetFocus
Me.OTHHOSP.ValidationRule = "<> Null"
Me.OTHHOSP.ValidationText = "Please, name other hospital"
Me.Refresh
End If
End Sub
Private Sub OTHHOSP_LostFocus()
'If OTHHOSP.Value = "" Then
' MsgBox "Please, name other hospital"
' OTHHOSP.SetFocus
'End If
If IsNull(Me.OTHHOSP) Then
Me.OTHHOSP.SetFocus
MsgBox "Please, name other hospital"
End If
End Sub
Validation rule for some reason does not start working until I enter something in the field and then delete it to make it Null. That's why I added LostFocus event. When I am loosing focus from the field, I get the intended message, however the SetFocus command does not work.
Thank you.
Regards,
Irene