I am trying to use the GoToControl method, but it is not working. I have a field in a form named STORE that is being compared to another field in another form named LOCATION. If the data entered into the STORE field does not match the LOCATION, I have a msgbox pop up and I want the control to go back to STORE so the user cannot leave this field without the correct information entered.
If the user does enter the correct store, the focus goes to the next field, ACCOUNT.
Below is the code I am using. Everything is working, except after the message box pops up for entering incorrect data, the focus goes to the ACCOUNT field when it should go back to STORE.
Private Sub STORE_Exit(Cancel As Integer)
If (Forms!frm_Expenditures![STORE] <> Forms!frm_BudgetItemsSubform!txt_LOCATION) Then
Beep
MsgBox "That DeptID does not match the DeptID on file", vbOKOnly, "Error"
DoCmd.GoToControl "[STORE]"
ElseIf (Forms!frm_Expenditures![STORE] = Forms!frm_BudgetItemsSubform!txt_LOCATION) Then
DoCmd.GoToControl "[ACCOUNT]"
End If
End Sub
If the user does enter the correct store, the focus goes to the next field, ACCOUNT.
Below is the code I am using. Everything is working, except after the message box pops up for entering incorrect data, the focus goes to the ACCOUNT field when it should go back to STORE.
Private Sub STORE_Exit(Cancel As Integer)
If (Forms!frm_Expenditures![STORE] <> Forms!frm_BudgetItemsSubform!txt_LOCATION) Then
Beep
MsgBox "That DeptID does not match the DeptID on file", vbOKOnly, "Error"
DoCmd.GoToControl "[STORE]"
ElseIf (Forms!frm_Expenditures![STORE] = Forms!frm_BudgetItemsSubform!txt_LOCATION) Then
DoCmd.GoToControl "[ACCOUNT]"
End If
End Sub