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

Passing a value to a text box from a list box

Status
Not open for further replies.

webstaff

Technical User
Jan 2, 2003
97
GB
Hi Guys,

I have a list box on a form with a text box.

The list box draws names using DAO from my database, and I want to click on a name in the list box and in doing so I want that records id number to appear in the text box.

Is that possible?

Thanks again In advance
les

The code im using to feed my List box is as follows:

'lists code1
Dim rs3 As Recordset
Dim db3 As Database

Set db3 = OpenDatabase("C:\Documents and Settings\webstaff\Desktop\sbtProgramme\sbt2.mdb")
Set rs3 = db3.OpenRecordset("select * FROM males " & _
"ORDER By field_kcname")
Set passmale = rs3.Fields("field_id")
Do Until rs3.EOF
staffylistmales.AddItem rs3.Fields("field_title") & ", " & _
rs3.Fields("field_kcname") & _
" [" & rs3.Fields("field_id") & "]"

rs3.MoveNext
Loop
rs3.Close
Set rs3 = Nothing
' end of lists code1
 
Code:
Private Sub List1_Click()
Text1 = List1.Text
End Sub
Is that you want?
 
Assuming that the record's ID number is of an integer datatype, you could set the itemdata propery of each field in the listbox to the id number of the record.

i.e:

lstRecords.AddItem(your_item_stuff)
lstRecords.ItemData(lstRecords.NewIndex) = your_record_id

And then in on_click:

txtID.Text = CStr(lstRecords.ItemData(lstRecords.ListIndex))

Greetings,
Rick
 
Thanks, that looks good,

I got there in the end by using a combo cox instead of a list:

TextBox(5) = Mid(Combomales, InStr(Combomales, "[") + 1, InStr(Combomales, "]") - InStr(Combomales, "[") - 1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top