How to pass 2 parameters from a list box into a query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • superleochen
    New Member
    • Dec 2008
    • 13

    How to pass 2 parameters from a list box into a query?

    When I choose an item with 2 columns in a list box, and press a button, I hope to pass this 2 columns as parameters into a query?

    e.g.
    WHERE (((Career_Profi le.Job_Type)=Forms!Form_Deve lopment!Control _Job_Type) And ((Career_Profil e.Job_Level)=Forms!Form_Deve lopment!Control _Job_Level)

    The problem is that query only got the first column -"Control_Job_Ty pe" and never got the second one - "Control_Job_Le vel".

    What do you think?
    Attached Files
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    You need to reference the name of the combo box, then the appropriate column. The index starts at zero. For example:
    Forms!myForm!cb oDropDown.Colum n(0)
    Forms!myForm!cb oDropDown.Colum n(1)

    Comment

    • ajalwaysus
      Recognized Expert Contributor
      • Jul 2009
      • 266

      #3
      I concur with ChipR. Even though you have multiple columns, when creating a combo box, you need to bound the combo box to a single value that you can quickly reference. ChipR's solution helps you access the combo box by each column.

      Here s a quick look at bounding columns, FYI...


      -AJ

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Bound controls are certainly important. It is usual to bind a control to the underlying dataset in such cases. Only one column can be bound.

        However, I doubt (not certain) that SQL can access the Column function reference required to access both columns. If it turns out that it cannot, then I suggest setting another control to reflect the value of the other column using an AfterUpdate event procedure. It would not generally be necessary to bind this other control (TextBox or Label would probably be the easiest to use).

        Comment

        • superleochen
          New Member
          • Dec 2008
          • 13

          #5
          Problem Solved!

          Originally posted by NeoPa
          Bound controls are certainly important. It is usual to bind a control to the underlying dataset in such cases. Only one column can be bound.

          However, I doubt (not certain) that SQL can access the Column function reference required to access both columns. If it turns out that it cannot, then I suggest setting another control to reflect the value of the other column using an AfterUpdate event procedure. It would not generally be necessary to bind this other control (TextBox or Label would probably be the easiest to use).
          You're so right. If I access the second column using Forms!myForm!cb oDropDown.Colum n(1), it would only return the first row's second column, it doesn't reflect the value I choose from listbox.

          And I use "afterupdat e" to set another control to reflect the second column I "select", it works good!

          Thank you guys!

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I'm pleased to have helped.

            Well done for taking that on and getting the solution to work for you btw.

            Comment

            Working...