GoToControl question (1 Viewer)

tbeegz

Registered User.
Local time
Today, 07:41
Joined
Mar 28, 2002
Messages
10
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
 

ghudson

Registered User.
Local time
Today, 07:41
Joined
Jun 8, 2002
Messages
6,195
Instead of GoToControl, I would use the SetFocus method.

Me.YourControlName.SetFocus

HTH
 

mbentley

Registered User.
Local time
Today, 05:41
Joined
Feb 1, 2002
Messages
138
You may also want to make sure the code is attached to the AfterUpdate event of the control and not the BeforeUpdate event. Access doesn't seem to like the latter.
 

Users who are viewing this thread

Top Bottom