Results 1 to 7 of 7
  1. #1
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13

    Sorting Combobox?


    Hi,
    I have a combobox which displays a list of all the months and an "All Months" selection. I have done this using this sql statement.
    SELECT MonthName AS Filter, MonthName FROM qryMonths UNION SELECT '*' AS Filter, "All Records" AS MonthName From qryMonths;

    My problem is this query is being sorted alphabetically (by month name) despite me having it sorted by MonthID in qryMonths. How can I change the sorting of this combobox? Is there no manual way of just choosing? Can it be done in VBA? All I can find on the web is http://office.microsoft.com/en-ie/ac...005187786.aspx .
    Which doesn't work.
    Any suggestions?
    Thanks.

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Add the ID field to your query and then sort by it something like this:

    SELECT MonthName AS Filter, MonthName, MonthID FROM qryMonths UNION SELECT '*' AS Filter, "All Records" AS MonthName, MonthID From qryMonths ORDER BY [MonthID]

  3. #3
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    Quote Originally Posted by SoftwareMatters View Post
    Add the ID field to your query and then sort by it something like this:

    SELECT MonthName AS Filter, MonthName, MonthID FROM qryMonths UNION SELECT '*' AS Filter, "All Records" AS MonthName, MonthID From qryMonths ORDER BY [MonthID]
    Thanks but if I do that it displays an "All records" selection for each record rather than just one.
    I tried SELECT DISTINCT and DISTINCTROW but neither had any effect. Any suggestions?

  4. #4
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Do you have grouping switched on in the qryMonths query? If so this doesn't quite make sense if you want to order by ID.

  5. #5
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    Nope don't have grouping switched on. It's as simple as
    SELECT tblMonths.MonthName, tblMonths.MonthIDFROM tblMonths;

  6. #6
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    I think I see what's going on now - try this:

    SELECT MonthName AS Filter, MonthName, MonthID FROM qryMonths UNION SELECT '*' AS Filter, "All Records" AS MonthName, 1 as MonthID From qryMonths ORDER BY [MonthID]

    NB: just change the number 1 to whatever you need depending on if you want the 'All Records' option to be at the top or the bottom.

  7. #7
    Fionn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    13
    Quote Originally Posted by SoftwareMatters View Post
    I think I see what's going on now - try this:

    SELECT MonthName AS Filter, MonthName, MonthID FROM qryMonths UNION SELECT '*' AS Filter, "All Records" AS MonthName, 1 as MonthID From qryMonths ORDER BY [MonthID]

    NB: just change the number 1 to whatever you need depending on if you want the 'All Records' option to be at the top or the bottom.
    Thanks works grand.

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

Similar Threads

  1. Replies: 11
    Last Post: 01-12-2012, 07:55 PM
  2. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  3. Sorting by combobox problem
    By wsurritte in forum Access
    Replies: 11
    Last Post: 02-28-2011, 02:11 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 PM

Tags for this Thread

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