Adding an attachment to email (1 Viewer)


Registered User.
Sep 17, 2008
I’m trying to attach a PDF (EstimatePrint) as an attachment to my Outlook Message. Everytime I run it, it just hangs Outlook with NO errors.

I assume I’m not referring to the PDF correctly ??? If I take out the Add.Attachment it works fine !!
The code is below, any help would be appreciated.

Private Sub cmdEmailList_Click()
RunCommand acCmdSaveRecord
On Error GoTo Err_cmdEmail_Click

DoCmd.OpenReport "EstimatePrint", acViewReport, , "[EstimateID]=" & [ID]

' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "<H3><B>Dear Customer</B></H3>" & _
"Please find attached the quotation you requested recently.<br>" & _
"Should you require any further information then please do not hesitate to contact me.<br>" & _
"<br><br><B>Thank you</B>"

'Use the second SigString if you use Vista as operating system

SigString = "C:\Documents and Settings\" & Environ("username") & _
"\Application Data\Microsoft\Signatures\Tom.htm"

'SigString = "C:\Users\" & Environ("username") & _

If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Signature = ""
End If

On Error Resume Next
With OutMail
.To = [Contact e-Mail]
.CC = ""
.BCC = ""
.Subject = [Site Address] & "- Quotation"
.HTMLBody = strbody & "<br><br>" & Signature
'You can add files also like this
.Attachments.Add EstimatePrint
End With

On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing

Exit Sub

MsgBox Err.Description
Resume Exit_cmdEmail_Click

End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
End Function

what value do you give to "EstimatePrint" is it the full path to the file?
what value do you give to "EstimatePrint" is it the full path to the file?

Not sure what the full path is !!

The PDF "Estimate Print" is a temporary printfile created earlier in the function
Then that is your problem. You must give the Add method a full path to the file you want to attach.

eg c:\yourfoldername\anotherfolder\mypdfdoc.pdf

Users who are viewing this thread

Top Bottom