Query best practice or solution - question (1 Viewer)

DWC3ZZZ

New member
Local time
Today, 11:46
Joined
Oct 2, 2024
Messages
2
Hello everyone. Thanking you in advance for taking the time to read (and with any luck) point me in a reasonable right direction.
This is my first post in the forum so here goes..

I have inherited a Access database for training of personnel. The bulk of the data is in a single table.
[emp ID], [Module], [dateCompleted], [TrainingSessionNo], and a few other irrelevant fields. The table spans over a dozen+ years. The personnel may have taken the same course a couple of times in 1 year or missed the training for a couple of years.

21601.0110-Aug-2020
21608.0115-Sep-2021
20105.0124-Nov-2024
21201.0107-Jan-2023
21605.0109-May-2019
17803.0428-Nov-2023
17804.0228-Nov-2023
17806.0204-Feb-2022
17803.0413-Dec-2023
21601.0123-Apr-2024

I think that will give you the general idea. What I have been asked to do is produce a report with the last date taken for any and all courses for each of the personnel within the last 2 years.
01.0103.0404.0205.0106.0208.01
20124-Nov-2023
2127-Jan-2024
17813-Dec-202328-Nov-2023
21623-Apr-2024
The data within the last two years is easy. I will query only the data (today's date - 2 years).

My first thought was to create a bunch of queries for each of the courses. ie. 01.01, 03.04 etc.. there are not really a great deal of them about and pull them into 1 query.
I am assuming there is a much simpler way to do this without creating a bunch of separate queries and linking them based employee ID? A cross tab query sparks my interest but I have not used them before.

Again, any and all suggestions will be greatly appreciated!
 
Yes a cross tab can probably do what you want.

Pull the fields you want into the query designer. (As per your list above)
Change the query type to crosstab

In the total selection select Group By for the emp_Id and Module
In the total selection for the DateCompleted select Max
In the crosstab selector select Row Heading for the empid, Column Heading for the module and Value for the date.

See what it looks like.
 
Last edited:
When you create the crosstab, you will choose the Max() option for the date.
 
The bulk of the data is in a single table
Just my opinion, but before any queries can be developed, you should normalize your data into a relational format. From what you have said so far, it appears you will need:
  1. An Employee table to hold employee data
  2. A Module table to hold Module names and other data related to each Module
  3. A TrainingSession table to hold data related to each training class or session within each Module
  4. A TrainingDate table to hold the various training session dates
  5. A TrainingCompleted table to hold each employees training completion result.
Each Employee may have training in multiple Modules
Each Module may have multiple Training Classes or Sessions
Each Class or Session may have multiple Dates they are taught
Each Training Session Date has one result for each Module for each Session for each Employee (Training was Completed Yes/No)

I don't know what a "Module" is, but I am using it as a category for training classes.
 
You've got 2 things to accomplish--a logical one (finding the MAX date) and formatting (making the thing easy for others to consume).

I would accomplish the logical one in Access and the formatting one in Excel. This is the query you need in Access to find the MAX date:

Code:
SELECT [emp ID], Module, MAX(dateCompleted) AS LastCompleted
FROM YourTableNameHere
GROUP BY [emp ID], Module
ORDER BY [emp ID], Module

Run that and then copy that into a new Excel file on a tab called 'Data'. Then make a new called 'Report'. On the Report tab you make a pivot table (which is essentially a cross tab query but better). You can have the Modules as column/row headings and then employees as row/column headings or vice versa. You can then allow users to filter data, you can add totals, etc.
 
there are 3 queries i made (numbered according as to the rank i made them).
3_qryFinal will be your query (note access replaces your dot (.) with underscore (_) on the module number).
 

Attachments

Seems to me that, in line with @LarryE's comment on db structure, there is the question of can you identify those current employees that have not taken any training courses in the last two years. That question can be raised with whoever wants the report, and may illustrate the limitations of the current database that can be used leverage improvements.
 
You can create a query based on your table. Add the course date. Then create a report based on this query. Create a form with a start date and end date field through which the report for each trainee appears from the beginning of the year until today.
Code:
SELECT tblWorkshop.ID, tblWorkshop.Department, tblWorkshop.DeviceType, tblWorkshop.HardwareType, tblWorkshop.RepairDate, tblWorkshop.Notes
FROM tblWorkshop
WHERE (((tblWorkshop.RepairDate)>=[forms]![frmRpt]![txtDateFrom] And (tblWorkshop.RepairDate)<=[forms]![frmRpt]![txtDateTo]))
ORDER BY tblWorkshop.RepairDate;

Code:
 On Error GoTo Err_cmdReport_Click

    Dim stDocName As String

    stDocName = "RptWorkshop"
    
    If Len(Me.txtdatefrom & vbNullString) = 0 Or Len(Me.txtDateTo & vbNullString) = 0 Then
        MsgBox "Please ensure that a report date range is entered into the form", vbInformation, "AZHAR"
        Exit Sub
    Else
        DoCmd.OpenReport stDocName, acPreview
    End If
Exit_cmdReport_Click:
    Exit Sub

Err_cmdReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdReport_Click
 

Users who are viewing this thread

Back
Top Bottom