Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85

    A “MaxOfDate” Issue on One of Our Reports

    Hello,

    I am having a “MaxOfDate” issue in our database, and I can’t seem to figure it out.

    Here’s what’s going on:

    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.

    The report is laid out as follows:
    CUA# (the assigned vehicle number)
    AlternateID (the name that the department gives to it)
    Date of last PM (Preventive Maintenance) service
    Status (whether it is “Current”, “30 days past due”, “60 days past due”, or “Over 90 days past due”

    INFORMATION THAT MAY HELP:
    The “CUA#”, “CustomerID”, and/or “Customer Number” are all the same thing, and all refer to the vehicles assigned number.

    DATABASE DESIGN (relating to this issue):


    The “Service” table is setup as follows:
    ServiceID (AutoNumber)
    CUA# (tied to the “CUA#” on the master table, the “Vehicles” table)
    Date (the date that the service was performed ((and I know that we shouldn’t have used the word “DATE”!)))
    Mileage (the mileage of the vehicle at the time of the service)
    WorkItem (category of the work that was performed ((from a look-up table)))
    SubWorkItem (the sub- category of the work that was performed ((also from a look-up table)))
    The Query that is used for the “Service: DPS Due Report” is titled “qryMaxDPSDates”, and is setup as follows:
    Field: CustomerID; Table: Service; Total: Group By
    Field: AlternateID; Table: Vehicles; Total: Group By; Criteria: Like "dps*" Or Like "B-*"
    Field: Date; Table: Service; Total: Max; Sort: Ascending
    The SQL statement for that query is:
    SELECT Service.CustomerID, Vehicles.AlternateID, Max(Service.Date) AS MaxOfDate
    FROM Vehicles INNER JOIN Service ON Vehicles.CustomerID = Service.CustomerID
    GROUP BY Service.CustomerID, Vehicles.AlternateID
    HAVING (((Vehicles.AlternateID) Like "dps*" Or (Vehicles.AlternateID) Like "B-*"))
    ORDER BY Max(Service.Date);
    Two Modules titled “30_60_90” that are setup as follows:
    Option Compare Database
    Option Explicit

    'Used for our DPS vehicles ONLY
    Public Function pastdue(ByRef dtVal As Date) As String
    Select Case DateDiff("d", dtVal, Date)
    Case Is < 30
    pastdue = "Current"
    Case 31 To 60
    pastdue = "Due for Service"
    Case 61 To 90
    pastdue = "Over 60 days"
    'Case Else
    Case Is > 90
    pastdue = "Over 90 days"
    End Select
    End Function

    'Used for all vehicles that ARE NOT DPS vehicles
    Public Function pastdueAll(ByRef dtVal As Variant) As String
    If Len(dtVal & vbNullString) = 0 Then


    pastdueAll = "No Record Yet"
    Exit Function
    End If
    Select Case DateDiff("d", dtVal, Date)
    Case Is < 365
    pastdueAll = "Current"
    Case Is > 365
    pastdueAll = "Due for Service"
    End Select
    End Function

    Here is what I have found thus far:
    If I use the the “MAX” option in the “Date” column of the “qryMaxDPSDates”, I get this:
    Click image for larger version. 

Name:	MAX.png 
Views:	13 
Size:	26.4 KB 
ID:	15845
    …nothing dated past September of last year.


    If I use the the “MIN” option in the “Date” column of the “qryMaxDPSDates”, I get this:
    Click image for larger version. 

Name:	MIN.png 
Views:	13 
Size:	27.3 KB 
ID:	15846
    …more current dates, but still not accurate.


    The actual last service performed (MaxOfDate/MinOfDate) on “CUA# 162 – B-60 (Little Ugly)” was today, 03/21/2014. But, as you can see, that is not included in any of the results! And, just to be sure that it is just not “updated” or something for today, the same vehicle was PM serviced on 03/05/2014, and that date isn’t displaying either.

    AAAAArrrrrggggggg!!! Any ideas???

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I don't see the functions being called. Setting the functions aside, perhaps the service for "Little Ugly" that was performed is not being included in the query for a reason other than the date field.

    If you do a basic SELECT query and do not use the totals oprion "Group By" can you get the record to appear? If not the GROUP BY then perhaps your HAVING clause is the culprit.

  3. #3
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    Hey "ItsMe". Thanks for the quick response! OK, I'm "kinda" following you. I created a simple select query and all of the dates for "Little Ugly" showed up. I even put its number (162) in the "criteria" field and it still worked fine.

    What might be the next step???

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Start adding back criteria until the record is no longer retreived. When you identify the criteria that causes an issue, isolate it and try the others to be sure it is not more than one condition.

  5. #5
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    OK, HOLD THE PRESS!!! In an attempt to figure this out, I kept playing with the select query that I created in response to your last post. Here's what I found:
    • To start, I only had 3 fields in the query:
      • CustomerID
      • Date
      • ServiceID
        ...with no totals line and the query ran fine.

    • I then added the field "AlternateID" and ran it, and it ran fine again.
    • I then added "Like "dps*" Or Like "B-*"" to the Criteria field, and it ran fine again.
    • I then added the "totals" line, and changed "Date" from "Group By" to "Max", and I got the same results as the last run, all DPS dates.
    • I then deleted the "ServiceID" field and ran it, and the results came back like my original post, with all of the dates being in Sept. of 2013.


    Does this help at all???

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Where do you actually call these functions?

  7. #7
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    Um, I think that you mean in my report!?!? If so, there is a text box on the report titled "Status". The "Control Source" for it says "=pastdue([MaxOfDate])". Does that help???

    WAIT A MINUTE... Where the heck did you come from orange??? I should just hire you as my database assistant!!! lol

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It seems that having a totals query while using serviceID is the solution then? To be honest I am having a little trouble following the description of what works and what does not work.

    A totals query will not eliminate records but it may include some records in a group that you do not want them to be included in. I guess the ServiceID is the PK for the vehicle.

  9. #9
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    I guess the ServiceID is the PK for the vehicle.
    No. The “CUA#”, “CustomerID”, and/or “Customer Number” are all the same thing, and all refer to the vehicles assigned number.

    To be honest I am having a little trouble following the description of what works and what does not work.
    OK, where did I lose you?

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by dgaletar View Post
    OK, where did I lose you?
    Pretty much from the beginning. In post #5 you mentioned something is working. Why don't you start over and tell us what you are now using and what problem there is now, if any.

  11. #11
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    OK, from what I can figure, when the "ServiceID" field is included in the query, it returns ALL of the dates that the vehicle was serviced. When the "ServiceID" field is NOT included in the query, it returns ONLY the dates of September 2013.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Included where, in the SELECT statement? Post the SQL that causes all of the dates to be returned.

  13. #13
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    SELECT Service.CustomerID, Vehicles.AlternateID, Max(Service.Date) AS MaxOfDate, Service.ServiceID
    FROM Vehicles INNER JOIN Service ON Vehicles.CustomerID = Service.CustomerID
    GROUP BY Service.CustomerID, Vehicles.AlternateID, Service.ServiceID
    HAVING (((Vehicles.AlternateID) Like "dps*" Or (Vehicles.AlternateID) Like "B-*"))
    ORDER BY Max(Service.Date);

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Using the SQL you posted in post #13, how does this relate to the functions you posted in post #1?

  15. #15
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    SELECT Service.CustomerID, Vehicles.AlternateID, Max(Service.Date) AS MaxOfDate
    FROM Vehicles INNER JOIN Service ON Vehicles.CustomerID = Service.CustomerID
    GROUP BY Service.CustomerID, Vehicles.AlternateID
    HAVING (((Vehicles.AlternateID) Like "dps*" Or (Vehicles.AlternateID) Like "B-*"))
    ORDER BY Max(Service.Date);

    Well, from what I can see, the only difference is that in post #1, "Service.ServiceID" is missing from the SELECT & GROUP BY lines.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 22
    Last Post: 05-21-2013, 07:54 PM
  2. Renaming Reports issue
    By djclntn in forum Reports
    Replies: 4
    Last Post: 01-06-2012, 03:46 PM
  3. Pop Up Reports Maximised Issue
    By GraemeG in forum Reports
    Replies: 7
    Last Post: 07-27-2011, 07:55 AM
  4. Reports w/ sub-reports very slow to open
    By vaikz in forum Reports
    Replies: 2
    Last Post: 02-27-2011, 08:41 AM
  5. Access Reports drop sub-reports
    By Kevin Ellis in forum Reports
    Replies: 0
    Last Post: 11-19-2010, 03:28 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