"Required" is a reserved word in Access. Reserved words shouldn't be used as object names.
I modified your code to clean up some things.
Code:
Private Sub Command40_Click()
' Const chkDateFormat = "\#mm\/dd\/yyyy\#"
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim rs3 As DAO.Recordset
Dim recCheck As Variant
Dim IDCheck As Integer
Dim CodeCheck As Integer
' Dim ExpCheck As Date
' Dim i As Integer
' Dim ii As Integer
Set db = CurrentDb
Set rs1 = db.OpenRecordset("Training")
Set rs2 = db.OpenRecordset("TrainingCodes")
Set rs3 = db.OpenRecordset("Workers")
rs2.MoveFirst
Do Until rs2.EOF
If rs2![Required] Then
CodeCheck = rs2!Code
' Debug.Print "Code" & CodeCheck
rs3.MoveFirst
Do Until rs3.EOF
IDCheck = rs3!ID
recCheck = Nz(DLookup("ID", "Training", "WorkerID = " & IDCheck & " And Code = " & CodeCheck), 0)
If recCheck = 0 Then
' Debug.Print "ID" & IDCheck
' Debug.Print recCheck
With rs1
.AddNew
!WorkerID = IDCheck
!Code = CodeCheck
!tHours = rs2!Hours
!ProvidedBy = rs2!ProvidedBy
!Location = rs2!Area
!ExpiryDate = Date
.Update
End With
End If
rs3.MoveNext
Loop
End If
rs2.MoveNext
Loop
rs1.Close
rs2.Close
rs3.Close
Set rs1 = Nothing
Set rs2 = Nothing
Set rs3 = Nothing
' db.Close 'rule is: if you open it, close it. You didn't open dB
Set db = Nothing
End Sub
Then I modified it a lot..... sorry, I couldn't help myself
Code:
Private Sub Command40_Click()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim rs3 As DAO.Recordset
Dim sSQL As String
Dim recCheck As Variant
Dim IDCheck As Integer
Dim CodeCheck As Integer
Set db = CurrentDb
'select only the required training.
sSQL = "SELECT [Required], Code, Hours, Area, ProvidedBy"
sSQL = sSQL & " FROM TrainingCodes"
sSQL = sSQL & " WHERE [Required] = TRUE"
' Debug.Print sSQL
Set rs2 = db.OpenRecordset(sSQL)
Set rs3 = db.OpenRecordset("Workers")
rs2.MoveFirst
'loop through all of the required Training Codes
Do Until rs2.EOF
CodeCheck = rs2!Code
' Debug.Print "Code" & CodeCheck
rs3.MoveFirst
' find missing required training
Do Until rs3.EOF
IDCheck = rs3!ID
sSQL = "SELECT Workers.WorkerID, Training.ID, Training.Code"
sSQL = sSQL & " FROM Training INNER JOIN Workers ON Training.WorkerID = Workers.WorkerID"
sSQL = sSQL & " WHERE Workers.WorkerID = " & IDCheck & " AND Training.Code =" & CodeCheck & ";"
' Debug.Print sSQL
Set rs1 = db.OpenRecordset(sSQL)
'check for records found
If rs1.BOF And rs1.EOF Then 'no records - insert a new training record
Debug.Print "ID" & IDCheck
Debug.Print recCheck
sSQL = "INSERT INTO Training (WorkerID, Code, tHours, ProvidedBy, Location, ExpiryDate) "
sSQL = sSQL & " VALUES (" & IDCheck & ", " & CodeCheck & ", " & rs2!Hours & ", " & rs2!ProvidedBy & ", " & ", #" & Date & "#);"
' Debug.Print sSQL
' bypasses Access/ uses Jet to insert the record
db.Execute sSQL, dbFailOnError
End If
rs1.Close
rs3.MoveNext
Loop
rs2.MoveNext
Loop
On Error Resume Next
rs1.Close
rs2.Close
rs3.Close
Set rs1 = Nothing
Set rs2 = Nothing
Set rs3 = Nothing
' db.Close 'rule is: if you open it, close it. You didn't open dB
Set db = Nothing
End Sub
I don't know if "ProvidedBy" & "Location" are text fields or not. If they are text fields, delimiters will need to be added (In my version of the code, the blue text).
My code is untested, but I don't think there are any errors.......