Results 1 to 4 of 4
  1. #1
    lugnutmonkey is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    42

    Populating combo box

    I would like to populate a combo box with the years in which an order was taken.



    I have a table of orders with a Date_ordered field. I would like to use the years within that field to populate the combo box so that if there are order in 2011,2012 and 2013 only those three years will be available for selection.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Try

    SELECT Year(OrderDate) As TheYear
    FROM TableName
    GROUP BY Year(OrderDate)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    lugnutmonkey is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    42
    unfortunatly the year that I want to extract to fill my combo box is part of a long form date so the format is as follows:

    mm/dd/yyyy h:nn

    I am currently populating the combo box from a seperate table but I am starting to archive older order information. This method leaves several "dead" selections inside the combo box. I was hoping that by populating the CBox with the years in the order form I could avoid this problem

    the current SQl code is: SELECT Years.Year, Years.Year FROM Years UNION Select Null as AllChoice, "(All)" as Bogus From Years ORDER BY Years.Year;

    The extra mess between FROM and ORDER BY is so that a select all option exists. The years table this query refers to is simply a list of possible years and a unique ID.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    As long as the field is date/time the format is irrelevant; the Year() function will return the year.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 08-16-2012, 10:02 PM
  2. Populating table from combo box
    By mcguires99 in forum Forms
    Replies: 4
    Last Post: 12-13-2011, 09:48 AM
  3. Populating a combo box with a Calendar Control
    By system243trd in forum Access
    Replies: 0
    Last Post: 12-02-2011, 04:22 AM
  4. COMBO BOX Populating
    By b123 in forum Forms
    Replies: 14
    Last Post: 10-13-2010, 03:34 PM
  5. Populating other fields from combo box.
    By nkenney in forum Forms
    Replies: 1
    Last Post: 05-14-2009, 10:39 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