Results 1 to 4 of 4

Thread: [RESOLVED] How to use combo box TAG property

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    Resolved [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:
    1. Private Sub Get_vehicles()
    2.    Dim sSQL As String, cn As ADODB.Connection, rs As ADODB.Recordset
    3.    Dim str As String, Ind As Long
    4.    
    5.    Set cn = New ADODB.Connection 'weve declared it as a ADODB connection lets set it.
    6.    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    7.       "Data Source= c:\vra\RentalManager.mdb" 'this is the connection string.
    8.    cn.Open
    9.    Set rs = New ADODB.Recordset
    10.    
    11.    sSQL = "SELECT V_id, Year, Make, Model, Color FROM Vehicles "
    12.    sSQL = sSQL & "ORDER BY Make, Model"
    13.        
    14.    Set rs = cn.Execute(sSQL)
    15.    
    16.    Do Until rs.EOF = True
    17.       str = Right(rs.Fields("Year"), 2) & " " & Trim(rs.Fields("Make")) & " "
    18.       str = str & Trim(rs.Fields("Model")) & " " & Trim(rs.Fields("Color"))
    19.      
    20.       HistCombBx.AddItem str
    21.       HistCombBx
    22.                  
    23.       If rs.Fields("V_id") = Vehicle_id Then Ind = HistCombBx.ListCount
    24.      
    25.       rs.MoveNext
    26.    Loop
    27.        
    28.    rs.Close
    29.    Set rs = Nothing
    30.    Set cn = Nothing
    31.    
    32.    HistCombBx.ListIndex = Ind - 1
    33. End Sub

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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)

  3. #3

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    Re: How to use combo box TAG property

    thanks a lot guys, it really worked for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width