Save Report to PDF with a Custom Filename & Email..

C

cw

How do I adapt or combine my Code Button #2 below to include the Custom File-
naming as in Code Button #1 ?
- My Print to PDF button creates the custom filename perfectly.
- My Email code works fine also, but the PDF it attaches does not have a
custom filename?
- I cannot use the "acPreview report" option or "change the Caption of the
Report Form" becuase I hide the Access background using an API and so the
report can only be printed, emailed, or opened in Adobe Reader, but not
Previewed in Access.

I think the solution is to make my "Print" code "Save" the report first to
the C:\ drive, then run the "Email" code, and call that "Saved" report as the
Attachment?

Code Button #1
I use this code to Print a Report to PDF, creating a Custom PDF filename
(works great!):
-------------------------------------------
Private Sub Command11_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim stAcctNum As String
stAcctNum = "Acct_" & Me.CCFACCTNum

DoCmd.OutputTo acOutputReport, "rptServiceCancelForm", acFormatPDF, Format
(Date, " yyyy-mm-dd ") & stAcctNum & " Service Cancellation.pdf", True

End Sub
-------------------------------------------

Code Button #2
I use this code to Email the Report via Outlook, creating a Custom Subject &
Body (works great!):
-------------------------------------------
Private Sub Command2_Click()

On Error GoTo Err_Handler

Dim txtTo, txtCC, txtBCC, txtSubject, txtMessage As String
txtTo = "(e-mail address removed)"
txtCC = ""
txtBCC = ""

txtSubject = "Service Cancellation : " & Nz(Me.CCFAcctName, "") & " -
Acct#: " & Nz(Me.CCFACCTNum, "")
txtMessage = "Please note the following memo attached to this email:" &
vbCrLf & "Service Cancellation Form for : " & vbCrLf & "----------------------
--" & vbCrLf & " Customer Name : " & Nz(Me!CCFAcctName, "") & vbCrLf & "
Account Number : " & Nz(Me!CCFACCTNum, "") & vbCrLf & " Forward Address :
" & Nz(Me!CCFForwardAddress, "")

DoCmd.SendObject acSendReport, "rptServiceCancelForm", acFormatPDF, _
txtTo, txtCC, txtBCC, txtSubject, txtMessage, True

DoCmd.Close acForm, "frmServiceCancelForm"
DoCmd.Close acForm, "frmMsgBox"

Exit_Point:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End If
Resume Exit_Point

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top