[RESOLVED] How to use combo box TAG property
Can someone PLEASE show me how to set the property for each item in a combo box. Here is how I am addint items to the combo box and at the same time I want to store V_id in the TAG for each ITEM.
Then I want to read the TAG back when ever an item is clicked on. So please tell me how to read it back. I hope it could be very simple like Combobox.selecteditem.teg or something but since I never used it, I am not familiure with it. thanks.
VB Code:
Private Sub Get_vehicles()
Dim sSQL As String, cn As ADODB.Connection, rs As ADODB.Recordset
Dim str As String, Ind As Long
Set cn = New ADODB.Connection 'weve declared it as a ADODB connection lets set it.
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= c:\vra\RentalManager.mdb" 'this is the connection string.
cn.Open
Set rs = New ADODB.Recordset
sSQL = "SELECT V_id, Year, Make, Model, Color FROM Vehicles "
sSQL = sSQL & "ORDER BY Make, Model"
Set rs = cn.Execute(sSQL)
Do Until rs.EOF = True
str = Right(rs.Fields("Year"), 2) & " " & Trim(rs.Fields("Make")) & " "
str = str & Trim(rs.Fields("Model")) & " " & Trim(rs.Fields("Color"))
HistCombBx.AddItem str
HistCombBx
If rs.Fields("V_id") = Vehicle_id Then Ind = HistCombBx.ListCount
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set cn = Nothing
HistCombBx.ListIndex = Ind - 1
End Sub
Re: How to use combo box TAG property
The tag property is per control, not per item in the list.
The ComboBox and Listbox both support ItemData however, which is extra numeric data per list item (if you want to store text, you'll need to make your own array/collection to store it).
To set the ItemData you can do this:
HistCombBx.ItemData(HistCombBx.NewIndex) = rs.Fields("V_id")
And to read it back you can do this:
myVariable = HistCombBx.ItemData(HistCombBx.ListIndex)
Re: How to use combo box TAG property
Note that you can only store numeric data in the ItemData property.
Re: How to use combo box TAG property
thanks a lot guys, it really worked for me.