Link to home
Create AccountLog in
Avatar of seanlhall
seanlhallFlag for United States of America

asked on

How can I change the pdf file name using SendObject?

I currently was using Sendobject to send an email with a pdf attachment. The pfd would have the name of the report it was created from. I tried using DoCmd.SetProperty Report, acPropertyCaption, "Invoice " & Me.invoicenumber to change the file name but get the The control name 'InvoiceLH' is misspelled or refers to a control that doesn't exist.  InvoiceLH is the name of the report? I am not sure what the problem is.  Here is what I am using, it worked until I tried to change the property.

On Error GoTo ErrorControl_Click_Err

Dim strBody As String
Dim usercompany As String
Dim useroffice As String
StrSQL = "SELECT * FROM tblusersettings WHERE admin = True"
Set dbCur = CurrentDb()
Set rstFTPParams = dbCur.OpenRecordset(StrSQL, dbOpenDynaset, dbSeeChanges)
If rstFTPParams.EOF Then
MsgBox "Please enter company information in the user settings"
Stop
Else
 
'Email Client with attachment'
    strBody = "Dear valued client," & vbCrLf & vbCrLf & _
    "Your invoice is attached. Please remit payment at your earliest convenience." & vbCrLf & vbCrLf & _
    "IF YOU BELIEVE YOU HAVE RECEIVED THIS IN ERROR, PLEASE NOTIFY OUR OFFICE VIA PHONE " & rstFTPParams![officenumber] & vbCrLf & vbCrLf & _
    "Thank you for your business we appreciate it very much." & vbCrLf & vbCrLf & _
    "Sub-Total:" & Format(Me.Text165, "$#,##0.00") & vbCrLf & _
    "Tax:" & Format(Me.invoicetotal1, "$#,##0.00") & vbCrLf & _
    "Total Paid:" & Format(Me.discount1, "$#,##0.00") & vbCrLf & _
    "Total Due:" & Format(Me.Text194, "$#,##0.00") & vbCrLf & vbCrLf & _
    "Sincerely," & vbCrLf & vbCrLf & _
    rstFTPParams![companyname]
DoCmd.OpenReport Report, acViewPreview, , "[invoiceid]=" & Me![invoiceid], acWindowNormal
DoCmd.SetProperty Report, acPropertyCaption, "Invoice " & Me.invoicenumber
DoCmd.SendObject acSendReport, Report, acFormatPDF, _
    "" & Me.clientemail, _
    , _
    , _
    "Notification from " & rstFTPParams![companyname], _
    "" & strBody, _
     True
End If
rstFTPParams.Close
Set rstFTPParams = Nothing
Set dbCur = Nothing
ErrorControl_Click_Exit:
DoCmd.Close acReport, Report, acSaveNo

Exit Sub

ErrorControl_Click_Err:
Select Case Err.Number
Case 2501
Call LogErrorHidden(Err.Number, Err.description, "There has been an error on Form Invoice on Event (Send Invoice Email 2501)")
    MsgBox "The email was canceled and has not been sent", , "Email Delivery Canceled"
   
Case 3270
Call LogErrorHidden(Err.Number, Err.description, "There has been an error on Form Invoice on Event (Send Invoice Email 3270)")
    MsgBox "The email was canceled and has not been sent", , "Email Delivery Canceled"
   
Case Else
Call LogErrorHidden(Err.Number, Err.description, "There has been an error on Form Invoice on Event (Send Invoice Email General)")
    MsgBox "The email was canceled and has not been sent", , "Email Delivery Canceled"
   
End Select
   
Resume ErrorControl_Click_Exit
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

You cannot change the name of the file with sendobject.

If you want to rename the file you will have to create/export it with the name you want:
DoCmd.OutputTo acOutputReport, "YourReport", acFormatPDF, "C:\YourFolder\Yourfile.pdf"

...then use *Totally different* code (can't use send object here) to send the email and send the file along as an "attachment":
http://support.microsoft.com/kb/161088

(Lot's of extra work and sometimes not worth the effort)

;-)

JeffCoachman
Avatar of seanlhall

ASKER

From what I learned it sounds like the caption of the report is used as the file name when the pdf is created. I am trying to change the caption property before the report is made into a pdf.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks. If there is a better way to send an email please post.
<If there is a better way to send an email please post. >
There are "other" ways, none really any "Better" than another.
They are all just different and you need to evaluate each technique, based on what you need to do:
If you need External attachments, HTML Formatting, Importance, ...etc
...Then see the link I posted.

If you use SendObject or the code in the link, you may be prompted with the Outlook Security popup, then you may need this:
http://www.contextmagic.com/express-clickyes/

If you want to bypass Outlook altogether, you can use any of the dozen or so utilities that will do this as well:
http://www.dimastr.com/redemption/home.htm
http://www.fmsinc.com/products/emailer/
...et all.

Some of these utilities will allow for many more options than outlook (Scheduled Email sending, email Criteria, ...etc

;-)

Jeff
Finally,   ...to be perfectly honest...
<the caption of the report is used as the file name when the pdf is created. >
...I did not know this, so I learned something new as well...
;-)

Jeff