johankotze
Registered User.
- Local time
- Today, 22:09
- Joined
- Jul 3, 2016
- Messages
- 54
I found very old post in this forum - 2005, started by Ang. Tried to implement the code but can't get it to work
I keep getting the error in red at the .SaveAs line
Code:
Private Sub AmendmentInsurer_Click()
'Dim Variable_Note As String
Dim stDocName As String
Dim MyPath As String
Dim MyFileName As String
Dim Variable_To As String
Dim Variable_CC As String
Dim Variable_Subject As String
Dim Variable_Body As String
Dim Signature As String
Dim OutApp As Object
Dim OutMail As Object
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String
'I place the file on a different folder
'-------------------------------------------------------
MyPath = "\\JK_Server-PC\Users\JK_Server\My Documents\JKBrokers\Clients\PersonalClients\" & Forms!ClientInformation.LastName & " " & Forms!ClientInformation.Initials & " " & Forms!ClientInformation.Title & "_" & Forms!ClientInformation.ClientNr & "\Amendments\"
'State the filename.
'-------------------------------------------------------
MyFileName = "Amendment" & "" & "nr_" & Me.Amendment_nr & " " & Forms!ClientInformation.LastName & " " & Forms!ClientInformation.Initials & " " & Forms!ClientInformation.Title
'Let's print and save. Once you see it works, you can change True to False so that the file created is not opened after completion.
'----------------------------------------------------------------------------------------------------------------------------------
DoCmd.OpenReport "AmendmentPersonalSend", acViewPreview
DoCmd.OutputTo acOutputReport, "AmendmentPersonalSend", acFormatPDF, MyPath & MyFileName & ".pdf", False 'True
'Let's close our previewed report
'--------------------------------
'DoCmd.Close acReport, "AmendmentPersonalSend"
' The filepath for the attachment
'--------------------------------
If Not IsNull(Me.strHyperlink) Then
strFileName = Mid$(Me.strHyperlink, InStr(Me.strHyperlink, "#") + 1)
Else
strFileName = "Empty"
End If
'Set Variables
'---------------------------
Variable_To = Me.EmailTo
Variable_CC = Me.Text61 & ";" & Me.Text97
Variable_Subject = Me.Text32 & "/" & Me.Text36 & " " & Me.Text35 & " " & Me.Text34 & " - Service#: " & Amendment_nr
Variable_Body = "<FONT face=Verdana size=2><B>CLIENT: </B>" & Me.Text82 & " " & Me.Text35 & " " & Me.Text34 & "<BR>"
Variable_Body = Variable_Body & "<B>INSURER: </B>" & Me.Text41 & "<BR>"
Variable_Body = Variable_Body & "<B>POLICY#: </B>" & Me.Text32 & "<BR>"
Variable_Body = Variable_Body & "<B>SERVICE#:</B> <font color=red>" & Me.Amendment_nr & "</font><BR>"
Variable_Body = Variable_Body & "<B>AMENDMENT DATE:</B> " & Me.AmendDate & "<BR>"
Variable_Body = Variable_Body & "<CENTER><B>INSTRUCTION TO INSURER</B></CENTER>" & "<BR>"
Variable_Body = Variable_Body & "<hr style= 'color:Red;height:2pt;width:100%;' />"
Variable_Body = Variable_Body & Me.Amendment
Variable_Body = Variable_Body & "<hr style= 'color:Red;height:1pt;width:100%;' />"
Variable_Body = Variable_Body & "Groete/Regards<BR>"
'Set the ATTACHMENT field
'--------------------------------------------------------------------------------------
'If Not IsNull(strHyperlink) Then
'OutlookMail.Attachments.Add (strFileName)
'End If
'Set Outlook session with signature
'-----------------------------------------------
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail ' This creates a blank email and captures the users default signature.
.BodyFormat = 2 ' 2 = HTML format
.Send 'or use .Display
End With
Signature = OutMail.HTMLBody
With OutMail
.To = Variable_To
.CC = Variable_CC
.BCC = ""
.Subject = Variable_Subject
.Attachments.Add (MyPath & MyFileName & ".pdf")
.Attachments.Add (strFileName)
.HTMLBody = Variable_Body & Signature
.SaveAs = """\\JK_Server-PC\Users\JK_Server\My Documents\JKBrokers\Clients\PersonalClients\" & Forms!ClientInformation.LastName & " " & Forms!ClientInformation.Initials & " " & Forms!ClientInformation.Title & "_" & Forms!ClientInformation.ClientNr & "\Send Emails\" & Variable_Subject & ".msg", OlSaveAsType.olMSG"""
.Display 'or use .Send
.ReadReceiptRequested = True
End With
MsgBox "The Email has been send successfully to" & " " & Me.EmailTo
'Call Client confirmation
'------------------------
Call AmendConfir_Click
End Sub
I keep getting the error in red at the .SaveAs line