954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getting data from a list box.

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?

skalra63
Light Poster
30 posts since Feb 2006
Reputation Points: 13
Solved Threads: 0
 

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: http://www.daniweb.com/techtalkforums/thread26892.html

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

thank you, i will give it a go

skalra63
Light Poster
30 posts since Feb 2006
Reputation Points: 13
Solved Threads: 0
 

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

skalra63
Light Poster
30 posts since Feb 2006
Reputation Points: 13
Solved Threads: 0
 

Well you can get the listbox entry with:

listboxname.list(listboxname.listindex)

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?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

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 & "%' "

con.Open
RS.Open strSQL, con

If RS.EOF = True Then

RS.Close
con.Close

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

RS.Close
con.Close
End If

End Sub

skalra63
Light Poster
30 posts since Feb 2006
Reputation Points: 13
Solved Threads: 0
 

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

suchisuchi07
Newbie Poster
4 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You