Question : Exporting Access Report as PDF with a unique name

I have a Access report that I need to export as a PDF to a unique folder location however I need each page which already breaks by Member ID to be it's own PDF report and I need the PDF to name it self with Date() and Member ID.

Answer : Exporting Access Report as PDF with a unique name

Ok, this will fix the problem ... not a big deal.  I put that little form in there to run the report from for testing purposes and by default I generally run reports from a Form for reasons of passing parameters to queries & functions, etc.  Since you will be running the function in a Macro we just need to remove all the VBA references to the form.

1.) Open the report in Design View and change OnOpen Event to look like what's shown below.  

Private Sub Report_Open(Cancel As Integer)
    Me.Filter = strRptFilter
    Me.FilterOn = True
End Sub


2.) In Module1 remove or remark out the lines referring to the form ...  Forms!frmPrintLetter!Label10.Visible = False
The function should look like what's shown below.

Function PrintLetterPDF()
DoCmd.SetWarnings False
Dim rst As Recordset
Dim strFilename As String
Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT CBCLAIM FROM [qry_Letter Information First Letter] ORDER BY CBCLAIM;", dbOpenDynaset)
If rst.RecordCount > 0 Then
    rst.MoveFirst
    Do Until rst.EOF
        strFilename = "T:\EDI Back Scanning Documents\EDI\LTR-" & Right(rst!CBCLAIM, 10) & "-" & Format(Date, "YYYYMMDD") & ".PDF"
        strRptFilter = "[CBCLAIM]='" & rst!CBCLAIM & "'"
        DoCmd.OutputTo acOutputReport, "RPT_MediCare First Letter Request", acFormatPDF, strFilename, , , , acExportQualityPrint
        rst.MoveNext
    Loop
Else
    MsgBox "There are no records selected for the report!!"
    rst.Close
    Set rst = Nothing
    Exit Function
End If

MsgBox "Process complete.  Individual PDF's have been created."
rst.Close
Set rst = Nothing
End Function
Random Solutions  
 
programming4us programming4us