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")
OutApp.Session.Logon
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") & _
"\AppData\Roaming\Microsoft\Signatures\Mysig.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
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
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
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
ts.Close
End Function
______________________________________________________________
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")
OutApp.Session.Logon
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") & _
"\AppData\Roaming\Microsoft\Signatures\Mysig.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
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
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
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
ts.Close
End Function
______________________________________________________________