currently, i have got code that will let someone search a table in a database and return any possible recordsets into a listbox. however, i would like to be able to click on any of those items added to the list box, so that it will return other data from the chosen record. how would i go about doing this?

Did you look over the VB and Access Thread? In the listbox's on_Click event, you would initiate another query, searching for whatever data you need, and placing the retrieved info into the new text fields (or wherever).

Here is the link:

thank you, i will give it a go

i am not sure how to get the search data from the listbox entry to on_click() query

Well you can get the listbox entry with:


So, if for example, you had a listbox named "list1", you could get the highlight item in the list, and save it to a variable named lstdata by saying:

lstdata = list1.list(list1.listindex)

Or am I confused on exactly what you are having trouble with?

the listbox starts of empty. when a search is done, the records that are found, are displayed by ProductName in the listbox. what i need is to beable to click on one of these entries, so that the whole recordset can be viewed in the textboxes provided.

the following is the code i am using for a command button. when the button is hit, the string in the text box is used in the search, then populating the listbox

Private Sub cmdFindProductName_click()
Dim strSQL As String
Dim tb As String
tb = TxtSearchBox.Text

strSQL = "SELECT * from [product] where [productName] like '%" & tb & "%' "

RS.Open strSQL, con

If RS.EOF = True Then


MsgBox "Record was not Found", vbOKOnly, "No Match"
Do Until RS.EOF
listProductName.AddItem "" & RS("ProductName") 

End If

End Sub

i did have the same problem,in vb with access.but list1.list(list1.listindex) didnt work at all. btw, wat does listdata refer to....please let me know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.