Results 1 to 3 of 3
  1. #1
    Gaddy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    2

    Sort on Cascading Combo Box

    Hi there,



    I have a form which has two combo boxes:

    - cboLocationID
    - cboManagerID

    I have the following code in cboLocationID:

    Code:
    Private Sub cboLocationID_AfterUpdate()    Dim sManagerSource As String
    
    
        sManagerSource = "SELECT [tblManager].[ManagerID], [tblManager].[Forename] & ' ' & [tblManager].[Surname]" & _
                         "FROM [tblManager] " & _
                         "WHERE [LocationID] = " & Me.cboLocationID.Value
        Me.cboManagerID.RowSource = sManagerSource
    End Sub
    When I click into cboLocationID (the first combo box) it then filters cboManagerID (the second combo box) to show only the relevant records pertaining to a certain location. This is what I need it to do, however, I cannot get it to sort by name order; it will only sort by ManagerID (as it does with the code above), or if I put ORDER BY code in, I get errors depending where it is placed, or I get no results shown.

    The order needed - as it concatenates the managers forename and surname, e.g. Sam Fisher - is by the full name not ID.


    Can anyone assist me?

    P.S. My VBA and SQL knowledge is practically non-existent.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    All you need is an ORDER BY clause

    WHERE [LocationID] = " & cboLocation & " ORDER BY SURNAME, FORENAME"

  3. #3
    Gaddy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    2
    Thank you very much.

    I've altered my code so it now reflects this:

    Code:
    Private Sub cboLocationID_AfterUpdate()    
        Dim sManagerSource As String
        
        sManagerSource = " SELECT [tblManager].[ManagerID], [tblManager].[Forename] & ' ' & [tblManager].[Surname] " & _
                         " FROM [tblManager] " & _
                         " WHERE [LocationID] = " & Me.cboLocationID.Value & " ORDER BY Forename, Surname"
        Me.cboManagerID.RowSource = sManagerSource
        
    End Sub
    I altered what you gave me slightly and also put in a space between the first double quotes and the statement, i.e. " WHERE" - has done the trick.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cascading combo box - sort text numerically
    By motormouth1991 in forum Access
    Replies: 4
    Last Post: 05-23-2013, 06:49 AM
  2. Cascading combo box
    By Plix in forum Access
    Replies: 1
    Last Post: 02-20-2013, 06:54 AM
  3. Cascading Combo Box Help
    By euphoricdrop in forum Forms
    Replies: 3
    Last Post: 04-12-2011, 05:35 PM
  4. cascading combo
    By rexb in forum Forms
    Replies: 9
    Last Post: 10-26-2009, 04:10 PM
  5. Cascading Combo Box
    By nywi6100 in forum Forms
    Replies: 0
    Last Post: 10-23-2006, 01:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums