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:

…nothing dated past September of last year.
If I use the the “MIN” option in the “Date” column of the “qryMaxDPSDates”, I get this:

…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???