Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy next textbox question???

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hi everyone,
I have a form with 2 textboxes on it.

When the form loads text1 has focus by default because it is the first tab index. I have a hand scanner that puts data into the textbox. After the data goes in, what event should I use to set focus to text2.

This is what did not work

Private Sub Text1_Change()
Form1.text2.setfocus
End Sub

It captures the first character of a ten digit bar code and the other 9 go into text2. What's wrong? What should I be doing? I didn't see a afterUpdate in the event drop down list. Not used to VB.
Thanks all
PB
 

Use the keypress event and check for special characters that you scanner software can append to the string it retrieves (most use vblf or vbcr or both = vbnewline = vbcrlf).

Good Luck

 
It looks like the Change event is firing for each character that is entered thru the scanner. If the number of characters to be entered in Text1 is consistent, you could set the Maxlength property of the textbox to that number (let's say 10). Then modify your code in the Change event to this:
If Len(text1.text) >= Text1.maxlength then
Form1.text2.setfocus
End If
 
Check that the entire 10 bytes are there before changing focus.
if len(Text1.text) = 10 then
Form1.text2.setfocus
end if
 
Hey, thanks all of you.

I can't be certain that the input will always be a fixed length. Here is what I did on vb5prgrmr's suggestion.

' 13 is the numeric value-vbNewLine wasn't recognized
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Form1.Text2.SetFocus
End If
End Sub

Is there any problem with this? I'm pretty sure that the Ascii value isn't going to change between operating systems.
This works fine in my prog though.
Thanks.
PB
 

vbCr is the constant and no there should be no problem with that (or 13 like you have).

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top