Private Sub CreatePDF_Click()
Dim FileName As String
Dim FilePatch As String
FileName = "Geleidelijst" & Me.OrderNrCopy
Filepath = "C:\Users\A\Desktop\Test\" & FileName & ".pdf"
Forms("GeleidelijstForm").Filter = "[InvoerOrderNr]='" & Me![OrderNrCopy] & "'"
Forms("GeleidelijstForm").FilterOn = True
DoCmd.OutputTo acOutputForm, "GeleidelijstForm", acFormatPDF, Filepath
End Sub
It seems to create a PDF of all records, I only want it for the current record but it won't work.
And if possible, if the file already exist to create it with a different name by adding a number behind it or something but that's not necessary.
Thanks for any help.
CodePudding user response:
For anyone that needs the code to create a PDF file from the current record.
Had to change the entire code, it will save the current Form so the Report displays the accurate information and will refresh after, and ask you where you would like to safe the PDF file. Afterwards it will close the print preview.
Replace the FormName, NameOfColumnInTable, NameOfMatchingTextboxOnForum, ReportName and File to your own.
Private Sub CreatePDF_Click()
DoCmd.Save acForm, "FormName"
Me.Refresh
DoCmd.OpenReport "FormName", acViewPreview, , "NameOfColumnInTable = '" & Me.NameOfMatchingTextboxOnForum & "'"
DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, File, False, , , _
acExportQualityPrint
DoCmd.Close
End Sub