Link to home
Start Free TrialLog in
Avatar of ADawn
ADawn

asked on

Hide items in a combo box

Hello (Again),

Is there any way of hiding items in the combo box. This is the code snipnet. These items are loaded into the combo box when the form loads.

s_SQL = "SELECT fld_EquipName, fld_EqManuf, fld_EqLocation, fld_EqRackNum FROM tbl_EQ_Inventory Where Len(Trim(fld_EquipName & '')) > 0 " _
      & " Order By fld_EquipName ASC;"
     
      rst.CursorLocation = adUseClient
      rst.Open s_SQL, conn, adOpenKeyset, adLockOptimistic
               
      Do While Not rst.EOF
          Me.cboBoxes(1).AddItem rst("fld_EquipName").Value & " " & vbTab & " " & rst("fld_EqManuf").Value & " " & vbTab & " " & rst("fld_EqLocation").Value & " " & vbTab & " " & rst("fld_EqRackNum").Value
          rst.MoveNext
      Loop
      .Close

I don't want the "fld_EqLocation" and "fld_EqRackNum" to be shown in the combo box, but I need these values to be available (placed in textboxes) when the combo box item is selected by the user.

Any ideas on how I can achieve this?

ADawn
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try using the ItemData property of the ComboBox.  In your SQL stmt, you need to get the unique key or ID for each record.

s_SQL = "SELECT key, fld_EquipName, fld_EqManuf, fld_EqLocation, fld_EqRackNum FROM tbl_EQ_Inventory Where Len(Trim(fld_EquipName & '')) > 0 " _
     & " Order By fld_EquipName ASC;"
     
     rst.CursorLocation = adUseClient
     rst.Open s_SQL, conn, adOpenKeyset, adLockOptimistic
               
     With Me.cboBoxes(1)
       Do While Not rst.EOF
          .AddItem rst("fld_EquipName").Value & " " & vbTab & " " & rst("fld_EqManuf").value
          .ItemData(NewIndex) = rst(key)        
         rst.MoveNext
       Loop
     End with
     .Close

In the cboBoxes_Click event, you can determine the key value using: cboBoxes(1).ItemData (ListIndex).  Once you have the key value, you can easily get the selected record out of the rescordset to populate your text boxes.

Let me know if this helps.
Avatar of alaplume
alaplume

Comboitems have a tag property, you could hid it in there!
The Tag item in the combo box can only store 1 value, not the tag value for each items in the list.
Avatar of ADawn

ASKER

Array worked fine.

Thanks, ADawn