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

how to use vb coded query to populate a list box

Status
Not open for further replies.

montyb

Technical User
Sep 8, 2000
26
0
0
US
I have a form in which I would like a list box (or similar object) to be poplulated based on a letter entered in a text box. The user enters a letter in "txtFirstLetter" textbox. That letter should trigger a query that is something like ...

SELELCT CustCode FROM tblCustomer WHERE CustCode like "txtFirstLetter" *

I'm not sure how to properly write the code in vb, nor how to populate the list box (I'm assuming that is the proper object to use).

The purpose is for a user to see what CustCodes have already been used based on the letter they select in txtFirstLetter.

Thanks in advance
 
In txtFirstLetter's AfterUpdate event I would put

ListBoxName.Rowsource = "SELELCT CustCode FROM tblCustomer WHERE CustCode Like '" & txtFirstLetter & "'*'"

B-)
ljprodev@yahoo.com
ProDev
MS Access Applications
 
Two things I failed to mention...

1. Be sure that the listbox's RowSource Type is set at Table/Query

2. Note that there are apostrophes with in the quotation marks to denote that the variable is text and not numeric. ljprodev@yahoo.com
ProDev
MS Access Applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top