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

retreiving listbox value???

Status
Not open for further replies.

AccessDevJunior

Programmer
Apr 14, 2004
81
GB
hya,
i have a list box and a text box within a vb6 form.
i have put code on the afterupdate() event of the list box:
me.text1 = me.listbox1
in ms access the text box value will equal the selected row of the list box, but this is not the case in vb6.

does anyone know how i can use the listbox as a value?
 
Hi,

You could try:

Code:
Text1.Text = ListBox1.SelectedItem

Hope this helps

Harleyquinn
 
hya, thanx for the advice.
the code still does not seem to be working could it have anything to do with the listbox/textbox properties?
 
Hi,

What is not working with the code??

Could you put a break on that line of code and look at what the Listbox1.SelectedItem value is returning at runtime?

Harleyquinn
 
Private Sub List1_Click()
Text1.Text = List1.List(List1.ListIndex)
End Sub
 
hya
harleyquinn, im getting an error:
method or data member not found!
vladk code seems to have done the trick though, thanx for the help
 
Hi,

Sorry about that, I had forgotten I was in the VB6 forum and I posted a VB.NET solution by mistake.

Apologies

Harleyquinn
 
Let this noobie try to help you.... :)P)

I presume that you made a Connection with a database.

Code:
Private Sub List1_Click()
Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM Page1 WHERE Name = '" & List1.Text & "'", cn, adOpenDynamic
If Not rs.EOF And Not rs.BOF Then Text1.Text = rs.Fields("NAMEOFFIELD").Value

etc.... et......

End Sub

'Page1 is the name the AccesPage
'Name is the name of the field/row within the AccesPage

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
Accesevjr


You can use the listbox "click event".
When the client clicks on a name in the listox just capture the name in a var then process it. Theres also a dblclick event if you want the client to be extra sure thats the name they want.


Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top