I'm having a problem with a public sub I created. I have this in a module called globals and I reference it on the afterupdate event for every state field I have. The problem that I've run into is you can't access any of the commands such as setfocus. Perhaps I'm going about this all wrong.
I want it to check the string for the state they have entered and if it doesn't find it then give the error message and setfocus back to field. Everything works fine until it gets to the setfocus.
Private Sub HC_q1_State_AfterUpdate()
check_states (HC_q1_State)
End Sub
Public Sub check_states(variable As String)
Dim states As String
Dim compare_val As Integer
If Not IsNull(variable) Then
states = "AL AK CO CT DE FL GA HI ID MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PW PA TX UT VT VI VA WA WI"
compare_val = InStr(1, states, variable, 1)
If compare_val = 0 Then
MsgBox "Not a valid state"
variable.SetFocus <--Here is where I run into an error
End If
End If
End Sub
I want it to check the string for the state they have entered and if it doesn't find it then give the error message and setfocus back to field. Everything works fine until it gets to the setfocus.
Private Sub HC_q1_State_AfterUpdate()
check_states (HC_q1_State)
End Sub
Public Sub check_states(variable As String)
Dim states As String
Dim compare_val As Integer
If Not IsNull(variable) Then
states = "AL AK CO CT DE FL GA HI ID MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PW PA TX UT VT VI VA WA WI"
compare_val = InStr(1, states, variable, 1)
If compare_val = 0 Then
MsgBox "Not a valid state"
variable.SetFocus <--Here is where I run into an error
End If
End If
End Sub