Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    East London
    Posts
    3

    Unanswered: Combo box sychronising

    I would like to know how I would combine two combo boxes. For example in one combo box has a list of Directorates. The second combo box has a list of departments that come under a particular directorate. Once you select the Directorate, a list of possible departments appear for that directorate and is automatically updated once you select the department.

    Hope someone can help and thanks in advance.

  2. #2
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Re: Combo box sychronising

    In your departments combobox's On_Enter event type this code

    dim strSource as String
    strSource="SELECT * FROM Departments where Departments.DirectorateID=cboDirectorate"

    cboDepartment.ControlSource=strSource


    Originally posted by Sweetpea
    I would like to know how I would combine two combo boxes. For example in one combo box has a list of Directorates. The second combo box has a list of departments that come under a particular directorate. Once you select the Directorate, a list of possible departments appear for that directorate and is automatically updated once you select the department.

    Hope someone can help and thanks in advance.

  3. #3
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    Or here is another answer but a little longer.

    Here is a way to have a second combo box (perhaps listing products) based on another combo box (perhaps listing companies). Thus after the user chooses a company, he then sees only the products for that company in the second combo box.

    For criteria in the 2nd combo box (and to get to the query design mode of the combo box click on the 3 dots just to the right of the combo box's RowSource property):
    Like [Forms]![MyForm]![MyFirstComboBox]

    And for the OnEnter property of the 2nd combo box:
    =ctlRequery()

    And in any module:
    Public Function ctlRequery()
    ' Purpose: Use this in OnEnter property of a combobox that's based on another control
    ' that may have changed or based on records that may have changed
    ' since the form was first opened.

    On Error GoTo Err_ctlRequery

    ' Dim var.
    Dim ctl As Control

    ' Set var.
    Set ctl = Screen.ActiveControl

    ' Requery control.
    ctl.Requery

    Exit Function

    Err_ctlRequery:
    Exit Function

    End Function

    For an example of dependent combo boxes you can download my sample invoices database currently at the link toward the bottom of http://www.bullschmidt.com/login.asp and then on the Invoices Dialog check out the Invoice # combo box which is based on the Rep # combo box.

    One related point is that you probably wouldn't want to allow blanks (i.e. Nulls) in fields that are going to be used with Like in any criteria for that field. Otherwise the blanks wouldn't be shown.
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

  4. #4
    Join Date
    Oct 2003
    Location
    East London
    Posts
    3

    Thanks

    I will try that and let you know. Thanks for your help.

    Sweetpea

  5. #5
    Join Date
    Oct 2003
    Location
    East London
    Posts
    3

    Re: Combo box sychronising

    Thank you for your reply, I will try that and let you know.

    Sweetpea.

Posting Permissions

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