Cascading lists problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • visionstate@googlemail.com

    #1

    Cascading lists problem

    Hi there,
    I am building a database that requires cascading lists on a form.
    I currently have (I may be adding more later) 3 combo boxes on my form
    - Department, Surname and Forename.
    The user chooses the department they want and then the corresponding
    surnames from that department can be chosen from the Surname box and
    then the Forename depending on which Surname they chose.
    I then have a command button which produces the results of the
    selection in a query (basically running a query 'on the fly').
    The database is a training database so it is likely that there will be
    more than 1 record of training for each member of staff.
    The following is the code I have used for the combo boxes:

    Private Sub ComboDept_After Update()
    ComboSurname.Ro wSource = "Select Distinct Sheet1.Surname " & _
    "FROM Sheet1 " & _
    "WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
    "ORDER BY Sheet1.Surname; "
    End Sub

    Private Sub ComboSurname_Af terUpdate()
    ComboForename.R owSource = "Select Distinct Sheet1.Forename " & _
    "FROM Sheet1 " & _
    "WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
    "ORDER BY Sheet1.Forename ;"
    End Sub

    'Sheet 1' is the table it reads from.

    And this is the code in my command button:

    Private Sub Command5_Click( )
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    Dim strDept As String
    Dim strSurname As String
    Dim strForename As String
    Dim strTeam As String
    Dim strAttending As String
    Dim strTraining As String
    Set db = CurrentDb
    Set qdf = db.QueryDefs("T estQuery")

    If IsNull(Me.Combo Dept.Value) Then
    strDept = " Like '*' "
    Else
    strDept = "='" & Me.ComboDept.Va lue & "' "
    End If

    If IsNull(Me.Combo Surname.Value) Then
    strSurname = " Like '*' "
    Else
    strSurname = "='" & Me.ComboSurname .Value & "' "
    End If

    If IsNull(Me.Combo Forename.Value) Then
    strForename = " Like '*' "
    Else
    strForename = "='" & Me.ComboForenam e.Value & "' "
    End If

    If IsNull(Me.Combo Team.Value) Then
    strTeam = " Like '*' "
    Else
    strTeam = "='" & Me.ComboTeam.Va lue & "' "
    End If

    If IsNull(Me.Combo Attending.Value ) Then
    strAttending = " Like '*' "
    Else
    strAttending = "='" & Me.ComboAttendi ng.Value & "' "
    End If

    If IsNull(Me.Combo Training.Value) Then
    strTraining = " Like '*' "
    Else
    strTraining = "='" & Me.ComboTrainin g.Value & "' "
    End If

    strSQL = "SELECT StaffTeamQuery. * " & _
    "FROM StaffTeamQuery " & _
    "WHERE StaffTeamQuery. Dept" & strDept & _
    "AND StaffTeamQuery. Surname" & strSurname & _
    "AND StaffTeamQuery. Forename" & strForename & _
    "AND StaffTeamQuery. Team" & strTeam & _
    "AND StaffTeamQuery. Attending" & strAttending & _
    "AND StaffTeamQuery. Training" & strTraining
    qdf.SQL = strSQL
    DoCmd.OpenQuery "TestQuery"
    Set qdf = Nothing
    Set db = Nothing

    End Sub

    The problem I have is, for certain members of staff, where there are 2
    entries, it'll only display 1 entry and not the other and for some
    members of staff it will not display any information at all.
    Also, sometimes, if a persons Surname and Forename are left in the
    combo boxes from the previous open of the form, they're department is
    changed automatically in my table when a department is selected when
    the form is re-opened and a new search started.

    Sorry for the long winded post but I wanted to make it as detailed as
    possible as I am exhausted of ideas!
    Many Thanks!

    R.

  • MGFoster

    #2
    Re: Cascading lists problem

    visionstate@goo glemail.com wrote:
    Hi there,
    I am building a database that requires cascading lists on a form.
    I currently have (I may be adding more later) 3 combo boxes on my form
    - Department, Surname and Forename.
    The user chooses the department they want and then the corresponding
    surnames from that department can be chosen from the Surname box and
    then the Forename depending on which Surname they chose.
    I then have a command button which produces the results of the
    selection in a query (basically running a query 'on the fly').
    The database is a training database so it is likely that there will be
    more than 1 record of training for each member of staff.
    The following is the code I have used for the combo boxes:
    >
    Private Sub ComboDept_After Update()
    ComboSurname.Ro wSource = "Select Distinct Sheet1.Surname " & _
    "FROM Sheet1 " & _
    "WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
    "ORDER BY Sheet1.Surname; "
    End Sub
    >
    Private Sub ComboSurname_Af terUpdate()
    ComboForename.R owSource = "Select Distinct Sheet1.Forename " & _
    "FROM Sheet1 " & _
    "WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
    "ORDER BY Sheet1.Forename ;"
    End Sub
    >
    'Sheet 1' is the table it reads from.
    >
    And this is the code in my command button:
    >
    Private Sub Command5_Click( )
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    Dim strDept As String
    Dim strSurname As String
    Dim strForename As String
    Dim strTeam As String
    Dim strAttending As String
    Dim strTraining As String
    Set db = CurrentDb
    Set qdf = db.QueryDefs("T estQuery")
    >
    If IsNull(Me.Combo Dept.Value) Then
    strDept = " Like '*' "
    Else
    strDept = "='" & Me.ComboDept.Va lue & "' "
    End If
    >
    If IsNull(Me.Combo Surname.Value) Then
    strSurname = " Like '*' "
    Else
    strSurname = "='" & Me.ComboSurname .Value & "' "
    End If
    >
    If IsNull(Me.Combo Forename.Value) Then
    strForename = " Like '*' "
    Else
    strForename = "='" & Me.ComboForenam e.Value & "' "
    End If
    >
    If IsNull(Me.Combo Team.Value) Then
    strTeam = " Like '*' "
    Else
    strTeam = "='" & Me.ComboTeam.Va lue & "' "
    End If
    >
    If IsNull(Me.Combo Attending.Value ) Then
    strAttending = " Like '*' "
    Else
    strAttending = "='" & Me.ComboAttendi ng.Value & "' "
    End If
    >
    If IsNull(Me.Combo Training.Value) Then
    strTraining = " Like '*' "
    Else
    strTraining = "='" & Me.ComboTrainin g.Value & "' "
    End If
    >
    strSQL = "SELECT StaffTeamQuery. * " & _
    "FROM StaffTeamQuery " & _
    "WHERE StaffTeamQuery. Dept" & strDept & _
    "AND StaffTeamQuery. Surname" & strSurname & _
    "AND StaffTeamQuery. Forename" & strForename & _
    "AND StaffTeamQuery. Team" & strTeam & _
    "AND StaffTeamQuery. Attending" & strAttending & _
    "AND StaffTeamQuery. Training" & strTraining
    qdf.SQL = strSQL
    DoCmd.OpenQuery "TestQuery"
    Set qdf = Nothing
    Set db = Nothing
    >
    End Sub
    >
    The problem I have is, for certain members of staff, where there are 2
    entries, it'll only display 1 entry and not the other and for some
    members of staff it will not display any information at all.
    Also, sometimes, if a persons Surname and Forename are left in the
    combo boxes from the previous open of the form, they're department is
    changed automatically in my table when a department is selected when
    the form is re-opened and a new search started.
    >
    Sorry for the long winded post but I wanted to make it as detailed as
    possible as I am exhausted of ideas!
    Many Thanks!
    >
    R.
    >
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    You're doing too much. You can reduce the amount of VBA code like this:

    Set the RowSource property of the ComboSurname to this (all one line):

    SELECT Distinct Surname
    FROM Sheet1
    WHERE Dept = Form.ComboDept
    ORDER BY Surname

    Set the RowSource property of the ComboForename to this (all on line):

    SELECT Distinct Forename
    FROM Sheet1
    WHERE Surname = Form.ComboSurna me
    ORDER BY Forename

    The Form.ControlNam e allows the RowSource query to read the named
    control on the same form as the ComboBox.

    Then all you need in the ComboBoxes AfterUpdate events is a Requery:

    Private Sub ComboDept_After Update()

    Me!ComboSurname .Requery
    Me!ComboForenam e.Requery

    End Sub

    Private Sub ComboSurname_Af terUpdate()

    Me!ComboForenam e.Requery

    End Sub

    Since you are using these ComboBoxes as search criteria you should not
    bind them to a query or table (IOW, don't put anything in their
    ControlSource properties).

    After the Department, Surname, Forename have been selected then run the
    CommandButton "Command5" click event. BTW, you really have to change
    the name of that CommandButton to something more descriptive - it will
    make your future maintenance work a lot easier.

    You can reduce the If...Then statements to something like the following,
    which will allow the users to use wildcard characters.

    strSurname = " LIKE '*" & Me!ComboSurname & "*' "

    Now a user can enter Johns?n as the surname and get:

    Johnson
    Johnsen
    ... etc. ...

    --
    MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
    Oakland, CA (USA)

    -----BEGIN PGP SIGNATURE-----
    Version: PGP for Personal Privacy 5.0
    Charset: noconv

    iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
    XnZg0zwK9AKInlk EERsnn2Or
    =wjqz
    -----END PGP SIGNATURE-----

    Comment

    • visionstate@googlemail.com

      #3
      Re: Cascading lists problem


      MGFoster wrote:
      visionstate@goo glemail.com wrote:
      Hi there,
      I am building a database that requires cascading lists on a form.
      I currently have (I may be adding more later) 3 combo boxes on my form
      - Department, Surname and Forename.
      The user chooses the department they want and then the corresponding
      surnames from that department can be chosen from the Surname box and
      then the Forename depending on which Surname they chose.
      I then have a command button which produces the results of the
      selection in a query (basically running a query 'on the fly').
      The database is a training database so it is likely that there will be
      more than 1 record of training for each member of staff.
      The following is the code I have used for the combo boxes:

      Private Sub ComboDept_After Update()
      ComboSurname.Ro wSource = "Select Distinct Sheet1.Surname " & _
      "FROM Sheet1 " & _
      "WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
      "ORDER BY Sheet1.Surname; "
      End Sub

      Private Sub ComboSurname_Af terUpdate()
      ComboForename.R owSource = "Select Distinct Sheet1.Forename " & _
      "FROM Sheet1 " & _
      "WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
      "ORDER BY Sheet1.Forename ;"
      End Sub

      'Sheet 1' is the table it reads from.

      And this is the code in my command button:

      Private Sub Command5_Click( )
      Dim db As DAO.Database
      Dim qdf As DAO.QueryDef
      Dim strSQL As String
      Dim strDept As String
      Dim strSurname As String
      Dim strForename As String
      Dim strTeam As String
      Dim strAttending As String
      Dim strTraining As String
      Set db = CurrentDb
      Set qdf = db.QueryDefs("T estQuery")

      If IsNull(Me.Combo Dept.Value) Then
      strDept = " Like '*' "
      Else
      strDept = "='" & Me.ComboDept.Va lue & "' "
      End If

      If IsNull(Me.Combo Surname.Value) Then
      strSurname = " Like '*' "
      Else
      strSurname = "='" & Me.ComboSurname .Value & "' "
      End If

      If IsNull(Me.Combo Forename.Value) Then
      strForename = " Like '*' "
      Else
      strForename = "='" & Me.ComboForenam e.Value & "' "
      End If

      If IsNull(Me.Combo Team.Value) Then
      strTeam = " Like '*' "
      Else
      strTeam = "='" & Me.ComboTeam.Va lue & "' "
      End If

      If IsNull(Me.Combo Attending.Value ) Then
      strAttending = " Like '*' "
      Else
      strAttending = "='" & Me.ComboAttendi ng.Value & "' "
      End If

      If IsNull(Me.Combo Training.Value) Then
      strTraining = " Like '*' "
      Else
      strTraining = "='" & Me.ComboTrainin g.Value & "' "
      End If

      strSQL = "SELECT StaffTeamQuery. * " & _
      "FROM StaffTeamQuery " & _
      "WHERE StaffTeamQuery. Dept" & strDept & _
      "AND StaffTeamQuery. Surname" & strSurname & _
      "AND StaffTeamQuery. Forename" & strForename & _
      "AND StaffTeamQuery. Team" & strTeam & _
      "AND StaffTeamQuery. Attending" & strAttending & _
      "AND StaffTeamQuery. Training" & strTraining
      qdf.SQL = strSQL
      DoCmd.OpenQuery "TestQuery"
      Set qdf = Nothing
      Set db = Nothing

      End Sub

      The problem I have is, for certain members of staff, where there are 2
      entries, it'll only display 1 entry and not the other and for some
      members of staff it will not display any information at all.
      Also, sometimes, if a persons Surname and Forename are left in the
      combo boxes from the previous open of the form, they're department is
      changed automatically in my table when a department is selected when
      the form is re-opened and a new search started.

      Sorry for the long winded post but I wanted to make it as detailed as
      possible as I am exhausted of ideas!
      Many Thanks!

      R.
      >
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1
      >
      You're doing too much. You can reduce the amount of VBA code like this:
      >
      Set the RowSource property of the ComboSurname to this (all one line):
      >
      SELECT Distinct Surname
      FROM Sheet1
      WHERE Dept = Form.ComboDept
      ORDER BY Surname
      >
      Set the RowSource property of the ComboForename to this (all on line):
      >
      SELECT Distinct Forename
      FROM Sheet1
      WHERE Surname = Form.ComboSurna me
      ORDER BY Forename
      >
      The Form.ControlNam e allows the RowSource query to read the named
      control on the same form as the ComboBox.
      >
      Then all you need in the ComboBoxes AfterUpdate events is a Requery:
      >
      Private Sub ComboDept_After Update()
      >
      Me!ComboSurname .Requery
      Me!ComboForenam e.Requery
      >
      End Sub
      >
      Private Sub ComboSurname_Af terUpdate()
      >
      Me!ComboForenam e.Requery
      >
      End Sub
      >
      Since you are using these ComboBoxes as search criteria you should not
      bind them to a query or table (IOW, don't put anything in their
      ControlSource properties).
      >
      After the Department, Surname, Forename have been selected then run the
      CommandButton "Command5" click event. BTW, you really have to change
      the name of that CommandButton to something more descriptive - it will
      make your future maintenance work a lot easier.
      >
      You can reduce the If...Then statements to something like the following,
      which will allow the users to use wildcard characters.
      >
      strSurname = " LIKE '*" & Me!ComboSurname & "*' "
      >
      Now a user can enter Johns?n as the surname and get:
      >
      Johnson
      Johnsen
      ... etc. ...
      >
      --
      MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
      Oakland, CA (USA)
      >
      -----BEGIN PGP SIGNATURE-----
      Version: PGP for Personal Privacy 5.0
      Charset: noconv
      >
      iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
      XnZg0zwK9AKInlk EERsnn2Or
      =wjqz
      -----END PGP SIGNATURE-----
      Hi and thanks for your reply,
      I have gone through your reply and edited my database as you suggested
      but now, when I choose an option in ComboDept, I get no options in the
      Surname text box at all. Do you know why this would be? I've tried a
      couple of things myself but they don't seem to work...
      Thanks again!

      R.

      Comment

      • MGFoster

        #4
        Re: Cascading lists problem

        visionstate@goo glemail.com wrote:
        MGFoster wrote:
        >
        >>visionstate@g ooglemail.com wrote:
        >>
        >>>Hi there,
        >>>I am building a database that requires cascading lists on a form.
        >>>I currently have (I may be adding more later) 3 combo boxes on my form
        >>>- Department, Surname and Forename.
        >>>The user chooses the department they want and then the corresponding
        >>>surnames from that department can be chosen from the Surname box and
        >>>then the Forename depending on which Surname they chose.
        >>>I then have a command button which produces the results of the
        >>>selection in a query (basically running a query 'on the fly').
        >>>The database is a training database so it is likely that there will be
        >>>more than 1 record of training for each member of staff.
        >>>The following is the code I have used for the combo boxes:
        >>>
        >>>Private Sub ComboDept_After Update()
        >>>ComboSurname .RowSource = "Select Distinct Sheet1.Surname " & _
        >> "FROM Sheet1 " & _
        >> "WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
        >> "ORDER BY Sheet1.Surname; "
        >>>End Sub
        >>>
        >>>Private Sub ComboSurname_Af terUpdate()
        >>>ComboForenam e.RowSource = "Select Distinct Sheet1.Forename " & _
        >> "FROM Sheet1 " & _
        >> "WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
        >> "ORDER BY Sheet1.Forename ;"
        >>>End Sub
        >>>
        >>>'Sheet 1' is the table it reads from.
        >>>
        >>>And this is the code in my command button:
        >>>
        >>>Private Sub Command5_Click( )
        >> Dim db As DAO.Database
        >> Dim qdf As DAO.QueryDef
        >> Dim strSQL As String
        >> Dim strDept As String
        >> Dim strSurname As String
        >> Dim strForename As String
        >> Dim strTeam As String
        >> Dim strAttending As String
        >> Dim strTraining As String
        >> Set db = CurrentDb
        >> Set qdf = db.QueryDefs("T estQuery")
        >>>
        >> If IsNull(Me.Combo Dept.Value) Then
        >> strDept = " Like '*' "
        >> Else
        >> strDept = "='" & Me.ComboDept.Va lue & "' "
        >> End If
        >>>
        >> If IsNull(Me.Combo Surname.Value) Then
        >> strSurname = " Like '*' "
        >> Else
        >> strSurname = "='" & Me.ComboSurname .Value & "' "
        >> End If
        >>>
        >> If IsNull(Me.Combo Forename.Value) Then
        >> strForename = " Like '*' "
        >> Else
        >> strForename = "='" & Me.ComboForenam e.Value & "' "
        >> End If
        >>>
        >> If IsNull(Me.Combo Team.Value) Then
        >> strTeam = " Like '*' "
        >> Else
        >> strTeam = "='" & Me.ComboTeam.Va lue & "' "
        >> End If
        >>>
        >> If IsNull(Me.Combo Attending.Value ) Then
        >> strAttending = " Like '*' "
        >> Else
        >> strAttending = "='" & Me.ComboAttendi ng.Value & "' "
        >> End If
        >>>
        >> If IsNull(Me.Combo Training.Value) Then
        >> strTraining = " Like '*' "
        >> Else
        >> strTraining = "='" & Me.ComboTrainin g.Value & "' "
        >> End If
        >>>
        >> strSQL = "SELECT StaffTeamQuery. * " & _
        >> "FROM StaffTeamQuery " & _
        >> "WHERE StaffTeamQuery. Dept" & strDept & _
        >> "AND StaffTeamQuery. Surname" & strSurname & _
        >> "AND StaffTeamQuery. Forename" & strForename & _
        >> "AND StaffTeamQuery. Team" & strTeam & _
        >> "AND StaffTeamQuery. Attending" & strAttending & _
        >> "AND StaffTeamQuery. Training" & strTraining
        >> qdf.SQL = strSQL
        >> DoCmd.OpenQuery "TestQuery"
        >> Set qdf = Nothing
        >> Set db = Nothing
        >>>
        >>>End Sub
        >>>
        >>>The problem I have is, for certain members of staff, where there are 2
        >>>entries, it'll only display 1 entry and not the other and for some
        >>>members of staff it will not display any information at all.
        >>>Also, sometimes, if a persons Surname and Forename are left in the
        >>>combo boxes from the previous open of the form, they're department is
        >>>changed automatically in my table when a department is selected when
        >>>the form is re-opened and a new search started.
        >>>
        >>>Sorry for the long winded post but I wanted to make it as detailed as
        >>>possible as I am exhausted of ideas!
        >>>Many Thanks!
        >>>
        >>>R.
        >>>
        >>
        >>-----BEGIN PGP SIGNED MESSAGE-----
        >>Hash: SHA1
        >>
        >>You're doing too much. You can reduce the amount of VBA code like this:
        >>
        >>Set the RowSource property of the ComboSurname to this (all one line):
        >>
        > SELECT Distinct Surname
        > FROM Sheet1
        > WHERE Dept = Form.ComboDept
        > ORDER BY Surname
        >>
        >>Set the RowSource property of the ComboForename to this (all on line):
        >>
        > SELECT Distinct Forename
        > FROM Sheet1
        > WHERE Surname = Form.ComboSurna me
        > ORDER BY Forename
        >>
        >>The Form.ControlNam e allows the RowSource query to read the named
        >>control on the same form as the ComboBox.
        >>
        >>Then all you need in the ComboBoxes AfterUpdate events is a Requery:
        >>
        >>Private Sub ComboDept_After Update()
        >>
        > Me!ComboSurname .Requery
        > Me!ComboForenam e.Requery
        >>
        >>End Sub
        >>
        >>Private Sub ComboSurname_Af terUpdate()
        >>
        > Me!ComboForenam e.Requery
        >>
        >>End Sub
        >>
        >>Since you are using these ComboBoxes as search criteria you should not
        >>bind them to a query or table (IOW, don't put anything in their
        >>ControlSour ce properties).
        >>
        >>After the Department, Surname, Forename have been selected then run the
        >>CommandButt on "Command5" click event. BTW, you really have to change
        >>the name of that CommandButton to something more descriptive - it will
        >>make your future maintenance work a lot easier.
        >>
        >>You can reduce the If...Then statements to something like the following,
        >>which will allow the users to use wildcard characters.
        >>
        > strSurname = " LIKE '*" & Me!ComboSurname & "*' "
        >>
        >>Now a user can enter Johns?n as the surname and get:
        >>
        > Johnson
        > Johnsen
        > ... etc. ...
        >>
        >>--
        >>MGFoster:::mg f00 <atearthlink <decimal-pointnet
        >>Oakland, CA (USA)
        >>
        >>-----BEGIN PGP SIGNATURE-----
        >>Version: PGP for Personal Privacy 5.0
        >>Charset: noconv
        >>
        >>iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
        >>XnZg0zwK9AKIn lkEERsnn2Or
        >>=wjqz
        >>-----END PGP SIGNATURE-----
        >
        >
        Hi and thanks for your reply,
        I have gone through your reply and edited my database as you suggested
        but now, when I choose an option in ComboDept, I get no options in the
        Surname text box at all. Do you know why this would be? I've tried a
        couple of things myself but they don't seem to work...
        Thanks again!
        >
        R.
        >
        It works for me. Can you show me the SQL string for each ComboBox?
        Have you remembered to add the Requery to the dependent ComboBox in the
        main combo's AfterUpdate event?
        --
        MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
        Oakland, CA (USA)

        Comment

        • Larry Linson

          #5
          Re: Cascading lists problem

          Can one or both of you delete some of the past conversation from your reply?
          My finger's sore from all the scrolling I have to do to get to the latest.
          If you are going to quote every post in every post, at least post the newest
          on top. Thanks.

          Larry


          "MGFoster" <me@privacy.com wrote in message
          news:Dnyqg.2987 $PE1.961@newsre ad2.news.pas.ea rthlink.net...
          visionstate@goo glemail.com wrote:
          >MGFoster wrote:
          >>
          >>>visionstate@ googlemail.com wrote:
          >>>
          >>>>Hi there,
          >>>>I am building a database that requires cascading lists on a form.
          >>>>I currently have (I may be adding more later) 3 combo boxes on my form
          >>>>- Department, Surname and Forename.
          >>>>The user chooses the department they want and then the corresponding
          >>>>surnames from that department can be chosen from the Surname box and
          >>>>then the Forename depending on which Surname they chose.
          >>>>I then have a command button which produces the results of the
          >>>>selection in a query (basically running a query 'on the fly').
          >>>>The database is a training database so it is likely that there will be
          >>>>more than 1 record of training for each member of staff.
          >>>>The following is the code I have used for the combo boxes:
          >>>>
          >>>>Private Sub ComboDept_After Update()
          >>>>ComboSurnam e.RowSource = "Select Distinct Sheet1.Surname " & _
          >>> "FROM Sheet1 " & _
          >>> "WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
          >>> "ORDER BY Sheet1.Surname; "
          >>>>End Sub
          >>>>
          >>>>Private Sub ComboSurname_Af terUpdate()
          >>>>ComboForena me.RowSource = "Select Distinct Sheet1.Forename " & _
          >>> "FROM Sheet1 " & _
          >>> "WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
          >>> "ORDER BY Sheet1.Forename ;"
          >>>>End Sub
          >>>>
          >>>>'Sheet 1' is the table it reads from.
          >>>>
          >>>>And this is the code in my command button:
          >>>>
          >>>>Private Sub Command5_Click( )
          >>> Dim db As DAO.Database
          >>> Dim qdf As DAO.QueryDef
          >>> Dim strSQL As String
          >>> Dim strDept As String
          >>> Dim strSurname As String
          >>> Dim strForename As String
          >>> Dim strTeam As String
          >>> Dim strAttending As String
          >>> Dim strTraining As String
          >>> Set db = CurrentDb
          >>> Set qdf = db.QueryDefs("T estQuery")
          >>>>
          >>> If IsNull(Me.Combo Dept.Value) Then
          >>> strDept = " Like '*' "
          >>> Else
          >>> strDept = "='" & Me.ComboDept.Va lue & "' "
          >>> End If
          >>>>
          >>> If IsNull(Me.Combo Surname.Value) Then
          >>> strSurname = " Like '*' "
          >>> Else
          >>> strSurname = "='" & Me.ComboSurname .Value & "' "
          >>> End If
          >>>>
          >>> If IsNull(Me.Combo Forename.Value) Then
          >>> strForename = " Like '*' "
          >>> Else
          >>> strForename = "='" & Me.ComboForenam e.Value & "' "
          >>> End If
          >>>>
          >>> If IsNull(Me.Combo Team.Value) Then
          >>> strTeam = " Like '*' "
          >>> Else
          >>> strTeam = "='" & Me.ComboTeam.Va lue & "' "
          >>> End If
          >>>>
          >>> If IsNull(Me.Combo Attending.Value ) Then
          >>> strAttending = " Like '*' "
          >>> Else
          >>> strAttending = "='" & Me.ComboAttendi ng.Value & "' "
          >>> End If
          >>>>
          >>> If IsNull(Me.Combo Training.Value) Then
          >>> strTraining = " Like '*' "
          >>> Else
          >>> strTraining = "='" & Me.ComboTrainin g.Value & "' "
          >>> End If
          >>>>
          >>> strSQL = "SELECT StaffTeamQuery. * " & _
          >>> "FROM StaffTeamQuery " & _
          >>> "WHERE StaffTeamQuery. Dept" & strDept & _
          >>> "AND StaffTeamQuery. Surname" & strSurname & _
          >>> "AND StaffTeamQuery. Forename" & strForename & _
          >>> "AND StaffTeamQuery. Team" & strTeam & _
          >>> "AND StaffTeamQuery. Attending" & strAttending & _
          >>> "AND StaffTeamQuery. Training" & strTraining
          >>> qdf.SQL = strSQL
          >>> DoCmd.OpenQuery "TestQuery"
          >>> Set qdf = Nothing
          >>> Set db = Nothing
          >>>>
          >>>>End Sub
          >>>>
          >>>>The problem I have is, for certain members of staff, where there are 2
          >>>>entries, it'll only display 1 entry and not the other and for some
          >>>>members of staff it will not display any information at all.
          >>>>Also, sometimes, if a persons Surname and Forename are left in the
          >>>>combo boxes from the previous open of the form, they're department is
          >>>>changed automatically in my table when a department is selected when
          >>>>the form is re-opened and a new search started.
          >>>>
          >>>>Sorry for the long winded post but I wanted to make it as detailed as
          >>>>possible as I am exhausted of ideas!
          >>>>Many Thanks!
          >>>>
          >>>>R.
          >>>>
          >>>
          >>>-----BEGIN PGP SIGNED MESSAGE-----
          >>>Hash: SHA1
          >>>
          >>>You're doing too much. You can reduce the amount of VBA code like this:
          >>>
          >>>Set the RowSource property of the ComboSurname to this (all one line):
          >>>
          >> SELECT Distinct Surname
          >> FROM Sheet1
          >> WHERE Dept = Form.ComboDept
          >> ORDER BY Surname
          >>>
          >>>Set the RowSource property of the ComboForename to this (all on line):
          >>>
          >> SELECT Distinct Forename
          >> FROM Sheet1
          >> WHERE Surname = Form.ComboSurna me
          >> ORDER BY Forename
          >>>
          >>>The Form.ControlNam e allows the RowSource query to read the named
          >>>control on the same form as the ComboBox.
          >>>
          >>>Then all you need in the ComboBoxes AfterUpdate events is a Requery:
          >>>
          >>>Private Sub ComboDept_After Update()
          >>>
          >> Me!ComboSurname .Requery
          >> Me!ComboForenam e.Requery
          >>>
          >>>End Sub
          >>>
          >>>Private Sub ComboSurname_Af terUpdate()
          >>>
          >> Me!ComboForenam e.Requery
          >>>
          >>>End Sub
          >>>
          >>>Since you are using these ComboBoxes as search criteria you should not
          >>>bind them to a query or table (IOW, don't put anything in their
          >>>ControlSourc e properties).
          >>>
          >>>After the Department, Surname, Forename have been selected then run the
          >>>CommandButto n "Command5" click event. BTW, you really have to change
          >>>the name of that CommandButton to something more descriptive - it will
          >>>make your future maintenance work a lot easier.
          >>>
          >>>You can reduce the If...Then statements to something like the following,
          >>>which will allow the users to use wildcard characters.
          >>>
          >> strSurname = " LIKE '*" & Me!ComboSurname & "*' "
          >>>
          >>>Now a user can enter Johns?n as the surname and get:
          >>>
          >> Johnson
          >> Johnsen
          >> ... etc. ...
          >>>
          >>>--
          >>>MGFoster:::m gf00 <atearthlink <decimal-pointnet
          >>>Oakland, CA (USA)
          >>>
          >>>-----BEGIN PGP SIGNATURE-----
          >>>Version: PGP for Personal Privacy 5.0
          >>>Charset: noconv
          >>>
          >>>iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
          >>>XnZg0zwK9AKI nlkEERsnn2Or
          >>>=wjqz
          >>>-----END PGP SIGNATURE-----
          >>
          >>
          >Hi and thanks for your reply,
          >I have gone through your reply and edited my database as you suggested
          >but now, when I choose an option in ComboDept, I get no options in the
          >Surname text box at all. Do you know why this would be? I've tried a
          >couple of things myself but they don't seem to work...
          >Thanks again!
          >>
          >R.
          >>
          >
          It works for me. Can you show me the SQL string for each ComboBox? Have
          you remembered to add the Requery to the dependent ComboBox in the main
          combo's AfterUpdate event?
          --
          MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
          Oakland, CA (USA)

          Comment

          • John Welch

            #6
            Re: Cascading lists problem

            try double checking the column widths and number of columns for the combo
            boxes
            ---
            >
            Hi and thanks for your reply,
            I have gone through your reply and edited my database as you suggested
            but now, when I choose an option in ComboDept, I get no options in the
            Surname text box at all. Do you know why this would be? I've tried a
            couple of things myself but they don't seem to work...
            Thanks again!
            >
            R.
            >

            Comment

            • visionstate@googlemail.com

              #7
              Re: Cascading lists problem

              Hi guys,
              Thanks for all your replies.
              I've just managed to sort it as I was logging on...
              I'd left the 'row/source type' row blank. Simply changed it to
              table/query and it worked!
              Stupid mistake I know!
              Thanks again for all your help (especially MGFoster).
              Cheers,

              R.

              John Welch (remove remove) wrote:
              try double checking the column widths and number of columns for the combo
              boxes
              ---

              Hi and thanks for your reply,
              I have gone through your reply and edited my database as you suggested
              but now, when I choose an option in ComboDept, I get no options in the
              Surname text box at all. Do you know why this would be? I've tried a
              couple of things myself but they don't seem to work...
              Thanks again!

              R.

              Comment

              Working...