I have a form that has six textboxes:
txtUserName
txtOrderNum
txtAccountNum
txtAccountNum2
txtItemNum
txtQuantity
Each of these textboxes are user-editable and all of them use the "BeforeUpdate" to implement validation. All of that works well.
In addition, in the "AfterUpdate" event of the "txtOrderNum" textbox I have logic to look up the AccountNum and AccountNum2 from a linked table and populate the corresponding textboxes "txtAccountNum" and "txtAccountNum2". To set the values in these textboxes I have to use the code:
txtAccountNum.SetFocus
txtAccountNum.Value = strAccountNum
txtAccountNum2.SetFocus
txtAccountNum2.Value = strAccountNum2
All of this logic is also working properly.
The "AfterUpdate" event is firing essentially when the user tabs to or clicks on another control. The problem that I'm having is that when I set the focus to the "txtAccountNum" and "txtAccountNum2" controls to set these values I don't have the knowledge of what the user clicked on after updating the "txtOrderNum" control. As an example:
User enters a value in "txtOrderNum", then clicks on the "txtItemNum" field.
Before the focus goes to the "txtItemNum" field, the "txtOrderNum" event "AfterUpdate" fires.
The code grabs the values from the linked table; sets the focus to "txtAccountNum" and sets its value, then set the focus to "txtAccountNum2" and sets its value.
At this point the focus is on "txtAccountNum2", where I want it to be on the "txtItemNum" because that is what the user clicked on.
Any thoughts or ideas are appreciated.
Here is a dummied-down version of the code:
Private Sub txtOrderNum_AfterUpdate()
Me.txtAccountNum.SetFocus
Me.txtAccountNum.Value = "12354"
Me.txtAccountNum2.SetFocus
Me.txtAccountNum2.Value = "56789"
End Sub