MS-Access VBA, how do you keep a textbox active after SetFocus and selecting the text?

Viewed 9

The plan: I have a single form with a text box that I type a serial number into. [intUID] The subforms on this same form use this to query and display related information. After I typed a serial in, I needed to refresh to get the subforms to requery, see code below. This works fine. I then set focus back into the serial number text box, ready for the next entry. This also works fine.

The rub: I want the text box to stay fully selected when I get focus set back to it. That way, when the next serial is entered, it deletes the old one. My code does this (can be seen stepping through the code) until the "End Sub" when it unselects it!

Private Sub intUID_AfterUpdate()

'Refresh sub forms
Forms![frmMain]![q_AG_CenterLines_X subform].Form.Requery
Forms![frmMain]![q_AG_CenterLines_Y subform].Form.Requery

'Set focus back on the barcode
Forms![frmMain]![txtSchedule].SetFocus
Forms![frmMain]![intUID].SetFocus

'Select all the text in [intUID]
Forms![frmMain]![intUID].SelStart = 0
Forms![frmMain]![intUID].SelLength = Len(Forms![frmMain]![intUID])

End Sub

0 Answers
Related