+ Reply to Thread
Results 1 to 8 of 8

Display results of a 2-column ComboBox

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Display results of a 2-column ComboBox

    Hi,

    How do I have a 2-column ComboBox on a form display both column results after a selection has been made? I can get the first or second column to display after the selection, but not both. For example, column 1 are employee names and column are departments. After making a selection, I can only get either the name or the department to display in the ComboBox, not both.

    I've seen a couple of postings on this, but no resolution. Is it because it's just not possible with a ComboBox?

    Thanks,

    Lawrence
    Last edited by skysurfer; 09-29-2010 at 02:20 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display results of a 2-column ComboBox

    if you set the property

    combobox1.columncount=2

    you will see both columns, provided you didn't enter values in the property Combobox1.columnwidths.



  3. #3
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: Display results of a 2-column ComboBox

    snb,

    Yes, doing so will show both columns when the ComboBox is clicked on and the box expands to show the listed items. But after you make a selection, only one value from one column (either the bound or the text value) appears in the ComboBox.

    How do I get both values to appear?

    Lawrence

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Display results of a 2-column ComboBox

    Wouldn't a ListBox be better?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display results of a 2-column ComboBox

    As far as I know that isn't possible in VBA-comboboxes.
    The way I solve this is to show the values in the other columns in textboxes (or in any other userform object).
    You best consider a combobox as a selectingdevice not as an displaying device.

  6. #6
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: Display results of a 2-column ComboBox

    Hi RoyUK,

    A ListBox would work...only I have a space issue. Hmmm... I'll have to seriously consider it.

    Would it be possible to throw the bound AND text values into the ComboBox after the selection has been made? Say on click command? Something like this:

    Please Login or Register  to view this content.
    Oooops!

    It sort of works, except the ComboBox now displays the bound values TWICE. Instead of displaying "John Marketing", it displays "John John".

    what did I mess up?

    Lawrence

  7. #7
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: Display results of a 2-column ComboBox

    Okay, got it!

    Replace this line of code:

    Please Login or Register  to view this content.
    ...with this:

    Please Login or Register  to view this content.
    Lawrence
    Last edited by skysurfer; 09-29-2010 at 02:32 PM.

  8. #8
    Registered User
    Join Date
    11-17-2014
    Location
    London, England
    MS-Off Ver
    1991
    Posts
    1

    Re: Display results of a 2-column ComboBox

    4 Years late but here is the solution for anyone else looking. Figured it out by trial and error. This works for me:

    Dim Systems() As String
    ReDim Systems(1 To Field1Name_RowCount, 1 To 2)
    ComboBox1.List = Systems


    Private Sub ComboBox1_Change()
    With ComboBox1
    .Text = .Text & " " & .Value
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1