Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Posts
    18

    Unanswered: Populating Second Combo Box Based on Criteria from First Combo Box

    Hi.

    I have a form with two combo boxes. Based on the record selected in the first combo box, I want to select all records that match and, populate the second combo box. I have this part working but, when I select a record (any record) from the second combo box, the first record in the drop-down list always appear. Can anyone tell me what I am doing wrong? Thanks.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Post the relevant code please
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2007
    Posts
    18
    Hi.

    Here's the row source code for the first combo box...

    SELECT tblPolicy.PolicyNo FROM tblPolicy ORDER BY tblPolicy.PolicyNo;

    In the Change Event for the first combo box, I do a requery on the second combo box so that when a different policy is selected in the first combo box, it will populate the second combo box with the corresponding ID's.

    Here's the row source code for the second combo box...

    SELECT tblInsure.ID FROM tblInsure WHERE (((tblInsure.PolicyNumber)=[Forms]![frm_Main]![cboPolicy]));

    The combo boxes are being populated correctly but I just cannot get the ID that I have chosen in the second combo box to appear.

    Thank you.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    So....the actual query contained and living in the RowSource property of the First ComboBox is:

    SELECT tblPolicy.PolicyNo FROM tblPolicy ORDER BY tblPolicy.PolicyNo;

    which in turn is populating the First ComboBox with Policy Numbers. Then by selecting a Policy Number, now populated within the First ComboBox, we take that Policy Number and let it play in a query so as to populate the Second ComboBox with (just) the Record ID of the Insurer which is ultimately supplied via code through the OnChange event (use OnClick) of the First ComboBox.

    Looks good ... and should work but I'm a little confused with this statement:

    The combo boxes are being populated correctly but I just cannot get the ID that I have chosen in the second combo box to appear.
    Appear where? If the ComboBoxes are "being populated correctly" then, what are you seeing? Are you trying to populate a Form or Report with your selection from the Second ComboBox?

    In any case....make sure you are actually dealing with the Column of data you intend to deal with in either of your ComboBoxes. What you see may not be what you're getting. You code to fill the RowSource property of the Second ComboBox may need to look perhaps something like this:

    Me.secondComboBoxName.RowSource="SELECT tblInsure.ID FROM tblInsure WHERE (((tblInsure.PolicyNumber)=[Forms]![frm_Main]![cboPolicy].Column(2)));"

    Maybe...

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  5. #5
    Join Date
    Apr 2007
    Posts
    18
    Thank you.
    With your suggestions, I was able to resolve the problem.
    Have a great day.

Posting Permissions

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