Dynamically Name the report attached to email?

  • Thread starter Thread starter niuginikiwi
  • Start date Start date
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
 
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
 
Back
Top