Hi I have the following Code that is working fine, but I need to add in additional criteria because depending on the job title determines the number of years for the refresher date.
Basically if the persons job title is Production Technician or Storeman, then their refresher date needs to be set to 1 year on from the course start date and if their job title is Quality Inspector or Sales Support their refresher date needs to be set 3 years on from the course start date.
I know that an IF Statement is needed, but I'm not sure how to apply it within the loop.
The code is placed in the On Load event of the form "frmHealth&SafetyMatrix-FireSafetyFireWarden"
The idea is that when ever the form is opened it automatically checks the course start date and assigns the refresher date according the above.
Any assistance would be most appreciated
I've also attached the part of the database I'm working on so that you can see how I'm working
Kind Regards
Basically if the persons job title is Production Technician or Storeman, then their refresher date needs to be set to 1 year on from the course start date and if their job title is Quality Inspector or Sales Support their refresher date needs to be set 3 years on from the course start date.
I know that an IF Statement is needed, but I'm not sure how to apply it within the loop.
The code is placed in the On Load event of the form "frmHealth&SafetyMatrix-FireSafetyFireWarden"
The idea is that when ever the form is opened it automatically checks the course start date and assigns the refresher date according the above.
Any assistance would be most appreciated
Code:
Option Compare Database
Private Sub Form_Load()
Dim StartDate As Date
Dim RefresherDate As Date
Dim JobTitles As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
' Open the database and recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM qryHealthSafetyMatrixFireSafetyFireWarden")
JobTitles = strJobTitles
' Check if the recordset contains any records
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst ' Move to the first record
' Loop through all records
Do While Not rs.EOF
StartDate = rs!dtmCourseStartDate
RefresherDate = DateAdd("yyyy", 3, StartDate)
rs.Edit
rs!dtmFireWardenMarshallRefresherDate = RefresherDate ' Update field value
rs.Update
rs.MoveNext ' Move to the next record
Loop
Else
MsgBox "No records found."
End If
' Clean up
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
I've also attached the part of the database I'm working on so that you can see how I'm working
Kind Regards