(Follow-on from: MS access Split report and export each row as a PDF )
I am exporting files to PDF based on a a report. Initially to get it working I was naming the PDF files after the Table's ID field which worked but now I want to name it after the Job Number Field and the current date as number but when I change the button function to that it's not working. I think the syntax and formatting are fine but it still won't work.
The Code below is the entire button code which works and exports each row as its PDF
Private Sub Toggle2_Click()
Dim sPath As String
Dim sFile As String
Dim sReport As String
Dim rs As DAO.Recordset
sPath = "C:\Users\murtaghd\Documents\files\"
sReport = "export"
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Import")
Do While rs.EOF = False
DoCmd.OpenReport sReport, acViewPreview, , "ID = " & rs!ID, acHidden
sFile = sPath & rs!ID & ".PDF"
DoCmd.OutputTo acOutputReport, sReport, acFormatPDF, sFile
DoCmd.Close acReport, sReport
rs.MoveNext
Loop
rs.Close
MsgBox "Export complete"
End Sub
I want to have it work where it uses job number and current date as the file name but it's not working with just the job number when
DoCmd.OpenReport sReport, acViewPreview, , "ID = " & rs!ID, acHidden
sFile = sPath & rs!Job_Number & ".PDF"
I tried formatting the Job_Number a few ways but every time there is an issue running the code


sFile = sPath & rs.Fields("Job Number").Value & ".PDF"sFile = sPath & rs.Fields("Job Number").Value & "_" & Format(Date, "yyyymmdd") & ".PDF"