Change the name of PDF file for emailing

123dstreet

Registered User.
Local time
Yesterday, 18:49
Joined
Apr 14, 2010
Messages
122
Hi All! I have a button on my form that opens outlook, and attaches the report for that form. In the "Attachment:" on the email, it will always read: "Sales Order.pdf". Currently, the button is a VBA onclick event, which goes thru the event and sends it to a Macro. Is there any way that I can alter this title of the pdf to have the Order ID #? I just don't know where to look to change this data, is there anybody that can help me?? thanks so much.
 
The current operation wasn't something you coded then?
 
No it was not. But is there anyway to control the filename of the pdf ?
 
Ah, for something that links to Outlook if you start tinkering with it you may end up with more problems if you're not well versed in VBA. There isn't a straightforward way, and I can't tell what the best approach would be without seeing the DB.

Here's a link that shows you how to rename files using the file system object:

http://www.techbookreport.com/tutorials/fso1.html
 
How about giving us the entire code and macro steps that are included (or just upload a copy of the database with bogus data)? I believe it can be done but it will require modifying the name AFTER the creation of the PDF and before it is attached to the email. So, depending on which code is being used (or macro actions) it may require a bit of a rewrite.
 
Hi, this is the vba event that calls the macro.

Code:
Private Sub Emailb_Click()
On Error GoTo Err_preview_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    Refresh
    stDocName = "S-Order Report"
    
    stLinkCriteria = "[S-Order].[Order ID] =" & Me.[Order ID]
    
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
    DoCmd.RunMacro ("E-mail SO Report")
Exit_preview_Click:
    Exit Sub
Err_preview_Click:
    MsgBox Err.Description
    Resume Exit_preview_Click
End Sub

The Macro Action is: SendObject, the Action Arguments are:
Object Type: Report
Object Name: S-Order Report
Output Format: PDF Format (*.pdf)
To: =IIf([ContactEmail] Is Null,Null,Left(Right([ContactEmail],Len([ContactEmail])-8),Len([ContactEmail])-9))
Subject: ="Sales Order: " & [Order ID]
Msg Text: "Please see attachment"

Does this help to narrow it down a bit??
 
You need to convert the macro to vba so that you can adjust the file name when the function is called. You will have to save the file to the users hard drive or network drive so that you can attach it to an email.
 
Thanks for all your help. I did change the whole thing to VBA, works like a mint now.
 

Users who are viewing this thread

Back
Top Bottom