how to set focus and select text inside text box

siamandm
BronzeLounger
Posts: 1267
Joined: 01 May 2016, 09:58

how to set focus and select text inside text box

Post by siamandm »

Hi all
i have a text box used for entering data using a bar code scanner,
when the bar code scanner enter data to the text box the cursor jumps to the next text box , i want the cursor stays in the current text box and select all text inside the text box after the bar code scanner enter data to it.
how to achieve this, please


regards

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to set focus and select text inside text box

Post by HansV »

The scanner software usually has an option to insert an Enter after scanning a code. See if you can turn this off.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1267
Joined: 01 May 2016, 09:58

Re: how to set focus and select text inside text box

Post by siamandm »

can we make a trick, by creating another text box and set the tab order in order the mouse cursor goes to the new text box ... and when the new text box is set focus ... move the cursor back to the txtSearch text box?

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to set focus and select text inside text box

Post by HansV »

You can use the On Got Focus or On Enter event for this:

Code: Select all

Private Sub TextBox2_GotFocus()
    Me.TextBox1.SetFocus
End Sub
Make sure that TextBox2 comes immediately after TextBox1 in the Tab Order of the form.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1267
Joined: 01 May 2016, 09:58

Re: how to set focus and select text inside text box

Post by siamandm »

thanks a lot , that's worked more than what i was expected.