Hide items in a combo box

ADawn
ADawn used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
Try put those values into an array..

Commented:
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.

Commented:
Comboitems have a tag property, you could hid it in there!
Ryan ChongSoftware Team Lead

Commented:
The Tag item in the combo box can only store 1 value, not the tag value for each items in the list.

Author

Commented:
Array worked fine.

Thanks, ADawn

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial