Display two columns in Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nedryerson
    New Member
    • Apr 2010
    • 7

    Display two columns in Access

    Hello,

    I'm working on a form in Access 2007, and specifically on a combo-box field that displays two columns in the drop-down menu. The problem is that once I make a selection, the field only displays one of the two columns in the filled out box (the column on the left). I'd like to have both columns displayed after making a selection. Does anyone how I can achieve that? Thanks in advance.

    John
  • patjones
    Recognized Expert Contributor
    • Jun 2007
    • 931

    #2
    Hi,

    Combo boxes display a single value after selection. But, I was able to do what you are suggesting by putting this in for the After Update event of the combo box:

    Code:
    Me.cbo.Value = Me.cbo.Column(0) & "     " & Me.cbo.Column(1)

    The obvious drawback here is that the combo box's actual value will now be whatever the combined columns are, and this is not a good way to design it. If you feel like you must display more than whatever the bound column is, I would drop a text box in next to the combo box and do it there, so as to keep the combo box single-valued.

    Pat

    Comment

    • nedryerson
      New Member
      • Apr 2010
      • 7

      #3
      Originally posted by zepphead80
      Hi,

      Combo boxes display a single value after selection. But, I was able to do what you are suggesting by putting this in for the After Update event of the combo box:

      Code:
      Me.cbo.Value = Me.cbo.Column(0) & "     " & Me.cbo.Column(1)

      The obvious drawback here is that the combo box's actual value will now be whatever the combined columns are, and this is not a good way to design it. If you feel like you must display more than whatever the bound column is, I would drop a text box in next to the combo box and do it there, so as to keep the combo box single-valued.

      Pat
      Hey Pat,

      Thanks for your response. I did what you suggested (I think), but I received the following message when I then tried to make a selection from the combo-box:

      Microsoft Access can't find the object 'Me.'
      If 'Me' is a new macro or macro group, make sure you have saved it and that you have typed its name correctly.

      I must admit that I know relatively little about Access, so I have no idea what this message is asking me to do. Any idea how to make it read that code correctly? Thanks again.

      John

      Comment

      • patjones
        Recognized Expert Contributor
        • Jun 2007
        • 931

        #4
        Hi,

        Can you post all the code you have so far?

        "Me" is just a shorthand way of saying whatever your current database object is (form, report, etc.) When you type "Me.", a list should pop up with various commands you can use in relation to the form, and also all the controls on the form. Also bear in mind that when I wrote "Me.cbo.Val ue", I was implying that you should replace "cbo" with whatever the name of your combo box is.

        Pat

        Comment

        • nedryerson
          New Member
          • Apr 2010
          • 7

          #5
          Hey Pat,

          Here's the code that I have right now:

          Private sub Facility_AfterU pdate()
          AfterUpdate.Fac ility.Value = AfterUpdate.Fac ilityID.Column( 0) & " " & AfterUpdate.Fac ilityName.Colum n(1)
          End Sub

          So the field name for the whole combobox is "Facility," the column on the left is "FacilityID ," and the column on the right is "FacilityNa me."

          Also, the two dropdown boxes at the top of the Visual Basic code window are set to "Facility" and "AfterUpdat e," if that helps. Thanks again.

          John

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            These lines

            Code:
            AfterUpdate.Facility.Value = AfterUpdate.FacilityID.Column(0) & " " & AfterUpdate.FacilityName.Column(1)
            need to be

            Code:
            Me.Facility.Value = Me.FacilityID.Column(0) & " " & Me.FacilityName.Column(1)
            Linq ;0)>

            Comment

            Working...