Results 1 to 11 of 11
  1. #1
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85

    Question How to get a query to sort the date properly...

    DATABASE FUNCTION:



    We have a database designed to track the information for our fleet of vehicles, and to keep track of the services that were performed on them. One particular set of vehicles (from the “Department of Public Safety (DPS))” are required to be serviced monthly, while the rest are on an as-needed basis.

    To help us accomplish this task we designed a report titled “Service: DPS Due Report”. It tells us which of the DPS vehicles have not been serviced in the last 30 days, 60 days, and 90 days.



    What does that mean to a lay person. Well, if you have a newer vehicle you will notice that, if you don't get your oil changed at the right interval your "change oil soon" light will come on. That is designed to remind you that your vehicles' oil is ready to be changed. You then take it to a service station and have the service performed. Once that service has been performed, the service technician will reset your "change oil soon" light so that it starts the cycle over again.


    Well, our security vehicles (we have 7 of them) pretty much run 24 hours a day, 7 days a week. Therefore we, the service technicians, need to tell them when they are due for an oil change. We try to service these vehicles every 30 days to keep them in the best condition possible.

    When the vehicle comes in for this service, (say Security Vehicle #1 for arguments sake), we enter the service date into our database under that specific vehicles' record.
    - If, at that point we run this report, the report will say that Security Vehicle #1's "Status" is "Current", and that the "Date of Last PM Srvc." was on "05/09/2014".
    - If we run the report 31 days from today, it will tell us that Security Vehicle #1's "Status" is "Over 30 Days" (from it's last service), and that the "Date of Last PM Srvc." was on "05/09/2014".
    - If we run the report 61 days from today it will tell us that Security Vehicle #1's "Status" is "Over 60 Days" (from it's last service), and that the "Date of Last PM Srvc." was on "05/09/2014".
    - If we run the report 91 days from today it will tell us that Security Vehicle #1's "Status" is "Over 90 Days" (from it's last service), and that the "Date of Last PM Srvc." was on "05/09/2014".


    This report is crucial to us knowing which vehicles are NOT current, and what order (date wise) we need to service them in. (I.E: If Security Vehicle #1 was last serviced on 09/19/13 and Security Vehicle #2 was last serviced on 09/18/13, we need to bring Security Vehicle #2 in for service first, as it has been longer since it's last service.)

    Now, to be clear, we have two (2) reports; one for the Department of Public Safety vehicles, and one for all of the rest of them. (FYI - Neither of these reports are functioning properly.)


    The strange thing is that the reports were working just fine until sometime early this year. But now they are messing up real bad.

    For example, if I run the query that handles these reports, I get the following results:

    CUA# Alternate ID MaxOfDate
    134 B-50 (Big Ugly) 9/19/2013
    137 DPS-6 9/20/2013
    149 B-40 9/23/2013
    162 B-60 (Little Ugly) 9/24/2013
    144 DPS-4 9/24/2013
    145 DPS-3 9/25/2013
    138 DPS-2 9/25/2013

    ...but if I look in my "Service" table, I have this in there:

    ServiceID CUA# Date Mileage WorkItem SubWorkItem
    330 162 5/6/2014 57505 1 Changed Oil & Filter
    331 162 5/6/2014 57505 11 Replaced PS parking light bulb
    332 162 5/6/2014 57505 11 Replaced license plate bulb
    333 162 5/6/2014 57505 4 Replaced front brake pads


    That means that CUA# 162 was last serviced on 05/06/2014, but the report is showing that it was last serviced on 09/24/2013.

    As you can see, Access is "Sorting" the "Date" column by the first number in the date, and "9" is the highest number (9/24/2013). That's why it keeps showing up as the first one! But when I sort them myself, 5/6/2014 is the MOST CURRENT date!

    Any idea how I can get the query to sort the date properly???

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Sounds like the SQL retrieving the data for your report is looking at the dates as text before sorting.

    What type of object is your report's Record Source based on? Query? Table?

    What code is being used to open, export, or print the report?

  3. #3
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    What type of object is your report's Record Source based on? Query? Table?
    ItsMe, YOU ARE JUST PERFECT!!! That's it! It's pulling the date from the "Service" table, where the "Data Type" of the Date field is... wait for it... that's correct... "SHORT TEXT"!!!!


    So now the question is, can I change that data type without somehow crashing my entire database, along with the local internet connection and
    (somehow) my car???

  4. #4
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    So I went in and changed it to "Date/Time", and got the following error message: "Operation is not supported for this type of object."

    (I feel the internet starting to crash on me...)

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Don't get too happy just yet.

    The Data Type is what matters. Because you stated that you can sort manually but not using the report, I am going to guess that the Data Type at the table level is Date/Time.

    Do not confuse the Data Type with the Format. I am not familiar with a format of "Short Text". If, in fact, you have a format of "Short Text", back up your DB and change that format to Short Date or another format available from the pulldown on the far right of the Format field (Under General Tab).

    Another area to consider is a query somewhere. If you do not use the correct syntax, a query will interpret the value of a date field as text. I suspect your problem lies in a query somewhere.

  6. #6
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    Well, actually, I think you were right when you had me look at the Data Type for the contributing table. In the "Service" table, there is a Field named "Date" (and before you haters blast me... I KNOW THAT THIS IS WRONG!!!). In the same table, the Data Type for the "Date" field IS "Short Text", and NOT "Date/Time".

    Therefore, I believe that your original guess was spot on, when you stated:
    What type of object is your report's Record Source based on? Query? Table?

    ...the report (
    Service: DPS Due Report) is based on a query (qryMaxDPSDates), and the query is based on a table (Service). And, as stated above, the "Date" field in the "Service" table is "Short Text", and not "Date/Time".

  7. #7
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    BTW... back up completed! Thx!!!

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You may experience issues using the name Date in a query. This is not a deal breaker.

    If the DB is not allowing you to adjust the field type, you will need to run an update query to the table. I would create a new column in the table and give it an appropriate name. Give your new column the Date/Time data type. Create an action query of the Update type. Reference your old column "Date" as [Date] in the update to option for your new column.

    If this is not working, study the fields in your "Date" column and look for typos that do not allow the conversion. An Update query may produce an error table named Paste Errors that will help to identify problem records.

    Alternatively, SQL can use an alias and a Date Qualifier (#) to interpret text and sort correctly.

  9. #9
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    OK, one step at a time...

    I would create a new column in the table and give it an appropriate name.


    DONE. New name: "
    ServiceDate"

    Give your new column the Date/Time data type.
    DONE.

    Wait... Error message: "CUA Vehicle Maintenance can't save... HOLD EVERYTHING!!! I just figured it ALL out!!!

    This is a linked database... and I was trying to make the changes to the table in the front end!

    I just went in to the back end and made the change from "Short Text" to "Date/Time".

    And guess what...

    THE REPORT WORKS PERFECTLY AGAIN!!!

    THANK YOU ItsMe!!! You are the best!!!

  10. #10
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    BTW ItsMe, I don't know if you remember, but this was something that you and I were working on before... here. You don't know how awesome it is to finally figure this out and have it working again!

    Thank you!!!

    DG

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Glad to hear. Some of the columns seamed familiar, yes.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-09-2013, 05:57 PM
  2. Sort Records Via Date (Newest first)
    By tweety in forum Forms
    Replies: 4
    Last Post: 01-28-2013, 09:23 AM
  3. Make report sort by IDs and then by Date
    By taimysho0 in forum Programming
    Replies: 4
    Last Post: 07-03-2012, 01:03 PM
  4. Date not Properly Formatted in Crosstab Query
    By eliascm in forum Queries
    Replies: 4
    Last Post: 02-10-2012, 04:49 AM
  5. Sort by date and year
    By Douglasrac in forum Queries
    Replies: 13
    Last Post: 04-07-2011, 10:02 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