| | |
getting data from a list box.
![]() |
•
•
Join Date: Feb 2006
Posts: 30
Reputation:
Solved Threads: 0
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: http://www.daniweb.com/techtalkforums/thread26892.html
Here is the link: http://www.daniweb.com/techtalkforums/thread26892.html
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:
Or am I confused on exactly what you are having trouble with?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
listboxname.list(listboxname.listindex)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
lstdata = list1.list(list1.listindex)
•
•
Join Date: Feb 2006
Posts: 30
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Looking for List Box help, please! (VB.NET)
- How to search from a database, selecting from a combo or list box in vb? (Visual Basic 4 / 5 / 6)
- List Box as input field also (JavaScript / DHTML / AJAX)
- How do I populate multiple column list box? (Visual Basic 4 / 5 / 6)
- Drive List Box Help Please for Error 68 (Visual Basic 4 / 5 / 6)
- list box --php issue (PHP)
- My list box (Java)
- "Error in linking List box with the VB6.0 database" (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: using Access in VB
- Next Thread: Reading bytes from binary file
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






