I have a query called qryGrpMedHMMScript which collates the data for a report repScriptHMM.
I have a button on a form which when clicked triggers the code below:
The code successfully generates individual pdf reports for all the records I want it to. However the issue is with the file name. The key (number and primary key) is correct for each pdf however all the other information returns as identical and matches the first record.
I can see why this would happen but not how to fix it!
I have a button on a form which when clicked triggers the code below:
Code:
Private Sub Command8_Click()
Dim rst As Recordset
Dim db As Database
Dim strSQL As String
Set db = CurrentDb()
Set rst = db.OpenRecordset("Select [Key] From [qryGrpMedHMMScript]")
rst.MoveFirst
Do Until rst.EOF
DoCmd.OpenReport "repScriptHMM", acViewPreview, , "Key = " & rst!Key, acHidden
DoCmd.OutputTo acOutputReport, "repScriptHMM", acFormatPDF, "C:\Users\tomiv\Desktop\File Dump\Scripts" & [Mill] & " " & "MFSP For" & " " & [Client Name] & " " & [Unit Name] & " " & [Diet] & " " & rst!Key & ".pdf"
DoCmd.Close acReport, "repScriptHMM"
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
strSQL = ""
End Sub
The code successfully generates individual pdf reports for all the records I want it to. However the issue is with the file name. The key (number and primary key) is correct for each pdf however all the other information returns as identical and matches the first record.
I can see why this would happen but not how to fix it!
Last edited by a moderator: