I tried using the 2nd option and it looped through and created the pdfs, however it only updated the first record, not the others. Can you see why its not looping properly?
Code:
Private Sub Command16_Click()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strSQL As String
Dim strRptName As String
Dim count As Integer
strRptName = "Report"
strSQL = "Select * From [Police Departments Query];"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
With MyRS
Do While Not MyRS.EOF
DoCmd.OpenReport strRptName, acViewPreview, , "[ID]=" & ![ID], acHidden
DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, [Application].[CurrentProject].[Path] & "\Aed letters\" & "Aed Letter " & ![Officer Name] & " " & Format(![Date of Incident], "MMMM dd, yyyy") & ".pdf"
DoCmd.Close acReport, strRptName, acSaveNo
CurrentDb.Execute "UPDATE [Main Table] SET [PDF Created and Emailed]=True, [Path to PDF]='" & [Application].[CurrentProject].[Path] & "\Aed letters\" & "Aed Letter " & ![Officer Name] & " " & Format(![Date of Incident], "MMMM dd, yyyy") & ".pdf' WHERE ID=" & ID
.MoveNext
Loop
End With
MyRS.Close
Set MyRS = Nothing
End Sub
I also tried the first method, and the fields are in the recordset but its saying they aren't being found. Could the fact a query is the recordset be affecting this?
Code:
.Edit
.[PDF Created and Emailed] = True
.[Path to PDF] = [Application].[CurrentProject].[Path] & "\Aed letters\" & "Aed Letter " & ![Officer Name] & " " & Format(![Date of Incident], "MMMM dd, yyyy") & ".pdf"
.Update