Dynamically Name the report attached to email?

N

niuginikiwi

Hi Guys,
The code below automatically fires up Outlook and attaches my report to an
email attachment and sends it to the address on a textbox on my form.

However, I want the attached report name to be taking its name in the form of
"Advice_AdviceNo_Today's Date"
That is the word Advice _ the advice number that is currenlty displayed on
my form _ and today's date.

Here is the code:
Private Sub btnEmailAdvice_Click()
On Error GoTo ProcError

Dim strDoc1 As String
Dim Email As String

strDoc1 = "rptInvoice"

If CurrentProject.AllReports(strDoc1).IsLoaded Then
DoCmd.Close acReport, strDoc1
End If

DoCmd.OpenReport strDoc1, acPreview, "qryInvoiceFilter", , acHidden
If Not IsNull(Me.EmailAddress) Then
DoCmd.SendObject acSendReport, strDoc1, acFormatPDF,
Me.EmailAddress, , , _
"Delivery Advice # " & Me.OrderID & " " & Date, _
"Please download/print the attached Delivery Advice and book in
produce using the Advice Number. PDF reader is needed to view the attachment.
Get your free copy of Adobe PDF reader at http://get.adobe.com/reader/", False
DoCmd.Close acReport, strDoc1
Else
MsgBox "There is no email address on record for " & _
vbCrLf & Me.CustomerID.Column(1) & vbCrLf & "Please verify and try
again later ..." _
, , "No E-mail Address"
Exit Sub
End If

MsgBox "Delivery Advice # " & Me.OrderID & " was successfully" & vbCrLf &
"E-mailed to " & Me.CustomerID.Column(1), , "Email Confirmation"
ExitProc:
Exit Sub
ProcError:
Resume ExitProc

End Sub
 
N

niuginikiwi

I have found the answer on how to doing this and I thought I might answer my
own question so others who have the same issue can use it.

in the onload event of the report

Me.Caption = " Invoice " & nameofcontrolsource
 

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