Results 1 to 6 of 6
  1. #1
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    53

    Union, Crosstab or other Query to find missing data

    I have three tables: VOR (that has the month and year a report was submitted), Vehicle_Data (That gives the information on the vehicle, tag number), and User_Data (that shows who is driving the vehicle).

    Each month the driver must submit a report that his vehicle is in working condition.

    What I would like my query to do is find those who have NOT turned in their report for the month. Need a little guidance on what query to use and the logic behind it.

    VOR Table:
    VOR_ID
    VEHICLE_ID
    RPT_MONTH
    RPT_YEAR

    VEHICLE Table:
    VEHICLE_ID
    TAG

    USER Table:
    USER_ID
    VEHICLE_ID


    CURRENT_USER (yes/no)

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by shuddle View Post
    I have three tables: VOR (that has the month and year a report was submitted), Vehicle_Data (That gives the information on the vehicle, tag number), and User_Data (that shows who is driving the vehicle).

    Each month the driver must submit a report that his vehicle is in working condition.

    What I would like my query to do is find those who have NOT turned in their report for the month. Need a little guidance on what query to use and the logic behind it.

    VOR Table:
    VOR_ID
    VEHICLE_ID
    RPT_MONTH
    RPT_YEAR

    VEHICLE Table:
    VEHICLE_ID
    TAG

    USER Table:
    USER_ID
    VEHICLE_ID
    CURRENT_USER (yes/no)
    Can you post a copy of your db or at least show us a pic of your relationships window.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    53
    I've attached a drawing of the relationships. I can't upload the database for security purposes.
    .
    Attached Thumbnails Attached Thumbnails relationships.jpg  

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Try:
    Code:
    SELECT Tbl_VOR.VehicleIDFROM Tbl_VOR
    WHERE (((Tbl_VOR.Rep_Year)=2024))
    GROUP BY Tbl_VOR.VehicleID
    HAVING (((Max(Tbl_VOR.Rep_Month))<[Month]));
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    A table is an entity; it's fields are attributes of that entity. Things that do not define the entity should not be in that table ( as a general rule). VehicleID and current user don't describe/define the user and should not be there. If you can agree with that, then you can see that userID does not belong in the vehicle table either as a way to define who currently drives a vehicle. For that you'd have a junction table, and the better way to define who currently drives a particular vehicle in that table would be to have start and end dates for each combination of driver and vehicle. Not only is your data not properly normalized (IMHO) you have no way to retain history. Currently when you uncheck a user you cannot assign them a different vehicle unless you can have multiple userID's - yet you can't because it's a PK field.

    All of that is likely the reason why you're having difficulty at present.
    EDIT - I wouldn't have separate fields for year and month either. Maybe one is enough, or two if you want to know when it was due and when it was filed. It seems you're looking for that based on your post question. Easy enough if the due field is empty.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Shuddle,

    This would be way easier to explain if we had data (fake data is ideal... or remove any PII kinds of stuff... Just export the 3 or 4 tables (the short version) to a new database and upload that...

    MonthList--(1,M)--MonthlyReport--(M,1)--Vehicle ---(1?,M?)--Driver

    MonthList is basically a table of dates (like the first of the month for a period of time).

    then it's super simple MonthList CROSS JOIN Vehicle returns something like this: (VehicleID, DueDate) and then you just subtract the Monthly Reports you have. (using maybe a LEFT JOIN between the (VehicleID, DueDate) and your MonthlyReport(VehicleID, SubmitDate) ).

    if you can post a sample database with just the necessary tables, I can bang out a query for you to solve this.

    The "MonthList" makes things infinitely easier, and you could just crank that out in Excel (start with 1/1/2024, end on the date you want, drag down, copy & paste into Access.) (Little wonder Excel is MSFT's moneymaker!)
    Last edited by madpiet; 12-06-2024 at 11:08 AM.

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

Similar Threads

  1. Replies: 32
    Last Post: 04-20-2022, 09:44 AM
  2. Replies: 4
    Last Post: 08-09-2017, 12:06 PM
  3. Convert Union Query to non-union help
    By Ekhart in forum Queries
    Replies: 2
    Last Post: 01-10-2017, 03:39 AM
  4. Replies: 4
    Last Post: 12-20-2015, 02:35 PM
  5. Replies: 2
    Last Post: 04-30-2014, 03:01 PM

Tags for this Thread

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