SendObject Attachment file name

L

LittlePenny

I have a command button on a form that uses a send object macro to
send a report. Everything works great. However I want to know is it
possible to choose the name of the attachment. I want the attachment
have the name of one of the fields in my form
[Forms]![frmMonthEndID]![Job Number]. Currently the attachment uses
the value in the caption control of the report.

My Code:



DoCmd.SendObject acSendReport, "rptID", acFormatRTF, _
"(e-mail address removed)", , , _
"Reprint for " & [Forms]![frmMonthEndID]![Job Number] & " ID: " &
_
[Forms]![frmMonthEndID]![ID], , False


Thanks


Little Penny
 
S

scott04

Lil Penny,

I do not use the same function but i do the following which allows me to
choose the name of my attachment:

Private Sub Command9_Click()
On Error GoTo ProcError
Dim strPath As String
Dim rst As DAO.Recordset
Dim AppOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set AppOutLook = CreateObject("Outlook.Application")
Set MailOutLook = AppOutLook.CreateItem(olMailItem)
Dim EContent As String
Dim stDocName As String

strPath = CurrentProject.Path
DoCmd.OutputTo acExport, "test query", acSpreadsheetTypeExcel9, strPath &
"\joint.xls", False, ""
MsgBox "The selected crap have been exported to the " & "file joint.xls" &
vbCrLf & "in the folder:" _
& vbCrLf & strPath, vbInformation, "Export Complete..."
With MailOutLook
..To = "[email protected]"
..Subject = "testomg"
..Importance = olImportanceHigh
..Attachments.Add strPath & "\joint.xls"
..Save
..Send

End With
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in cmdExportToExcel_Click event procedure..."
End Sub

I have a query run that upon saving it called it joint.xls. You can just
replace this with whatever you'd like for the attachment. You would also
have to change it when it calls for the attachment, .Attachments.Add strPath
& "\joint.xls". This only seems to work with Outlook but figured i would let
you know.
 

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