Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2024
    Posts
    2

    Converting text to numbers in order to limit results by value and order results by year & month

    I’ve got a Query that I’m trying to show results only for the months from January through the two digit month number that the user inputs. I’d like the results sorted by year, and then by month (within each year). Right now my results sort by year, but (i) not by month, and (ii) are not limited to the month that the user inputs (in this example I typed in “07” – but you can see that results include dates of 08/30/2024 and 09/01/2024 and 10/31/2024, etc). These are the results:



    Click image for larger version. 

Name:	QueryResults.png 
Views:	13 
Size:	271.3 KB 
ID:	51907
    I believe that the crux of the problem lies in the fact that my original data source has the Date stored as text. In the prior query (from which this query pulls data), I’ve used the Right and Left functions to pull the two digit month and the four digit year out of the date text field. But I assume that Access still treats these as text. Do I need to convert them to numeric values for this to work…and if so, how do I do that?

  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,652
    You haven't shown your SQL, but you can use the CDate() function on the text-date field to have it seen as a date instead of text. It will likely error if there are Null values in there, or invalid dates.
    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. Trying to understand why the order changes the results
    By SuperDude_123 in forum Queries
    Replies: 3
    Last Post: 04-04-2018, 03:48 PM
  2. Replies: 8
    Last Post: 03-20-2018, 11:30 AM
  3. Controlling the order of query results
    By AccessFanatic in forum Queries
    Replies: 7
    Last Post: 04-07-2017, 09:34 AM
  4. Replies: 2
    Last Post: 03-07-2016, 05:02 PM
  5. Query results order
    By Costa in forum Queries
    Replies: 6
    Last Post: 02-24-2010, 06:07 AM

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