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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping focus on Textbox while populating a Listbox 1

Status
Not open for further replies.

katoc

Programmer
Feb 15, 2005
52
0
0
US
Hi.

I have a simple form which contains a listbox and a textbox. the object of this form is to populate the listbox from data entered in the textbox. The data is barcodes that are scanned by a barcode scanner into the textbox. The problem is that after a barcode is scanned/entered, my code adds it to the listbox but never brings the focus back to the textbox so I can scan another barcode. I have to manually click on the textbox with the mouse. I want to just scan barcodes continuously without having to touch the mouse until I'm done. My code for this form is below. Any suggestions?

Code:
Private Sub TextBox1_AfterUpdate()
        List0.AddItem Item:=TextBox1.Value 
        TextBox1.Value = ""
        TextBox1.SetFocus    
End Sub
 
I don't think your text box ever loses the focus, which could be the problem. Try setting focus, in code, somewhere else, then moving it back. Something like...
Code:
Private Sub TextBox1_AfterUpdate()
        List0.AddItem Item:=TextBox1.Value 
        TextBox1.Value = ""
        [COLOR=red]List0.SetFocus[/color]
        TextBox1.SetFocus    
End Sub


Randy
 





Hi,

Could if be that the Change Event for these objects, is firing?
Code:
Private Sub TextBox1_AfterUpdate()[b]
  Application.EnabelEvents = False[/b]
        List0.AddItem Item:=TextBox1.Value 
        TextBox1.Value = ""[b]
  Application.EnabelEvents = True[/b]
        TextBox1.SetFocus    
End Sub



Skip,
[sub]
[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue][/sub]
 
Perhaps this ?
Private Sub TextBox1_AfterUpdate()
List0.AddItem Item:=TextBox1.Value
TextBox1.Value = ""
List0.SetFocus
TextBox1.SetFocus
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Whohoo, thanks Randy! So simple. I tried so many different combinations of code and this worked like a charm. Thanks also to Skip and PHV.

Skip, I didn't know you could disable the Change Events. Good to know for the future.

Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top