getting data from a list box.

Reply

Join Date: Feb 2006
Posts: 30
Reputation: skalra63 is an unknown quantity at this point 
Solved Threads: 0
skalra63 skalra63 is offline Offline
Light Poster

getting data from a list box.

 
0
  #1
Feb 28th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: getting data from a list box.

 
0
  #2
Feb 28th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 30
Reputation: skalra63 is an unknown quantity at this point 
Solved Threads: 0
skalra63 skalra63 is offline Offline
Light Poster

Re: getting data from a list box.

 
0
  #3
Feb 28th, 2006
thank you, i will give it a go
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 30
Reputation: skalra63 is an unknown quantity at this point 
Solved Threads: 0
skalra63 skalra63 is offline Offline
Light Poster

Re: getting data from a list box.

 
0
  #4
Feb 28th, 2006
i am not sure how to get the search data from the listbox entry to on_click() query
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: getting data from a list box.

 
0
  #5
Feb 28th, 2006
Well you can get the listbox entry with:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. lstdata = list1.list(list1.listindex)
Or am I confused on exactly what you are having trouble with?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 30
Reputation: skalra63 is an unknown quantity at this point 
Solved Threads: 0
skalra63 skalra63 is offline Offline
Light Poster

Re: getting data from a list box.

 
0
  #6
Feb 28th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: suchisuchi07 is an unknown quantity at this point 
Solved Threads: 0
suchisuchi07 suchisuchi07 is offline Offline
Newbie Poster

Re: getting data from a list box.

 
0
  #7
Aug 1st, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC