johankotze
Registered User.
- Local time
- Today, 03:34
- Joined
- Jul 3, 2016
- Messages
- 54
I have the following code on the ClickEvent of a button a form. I works well but I need to add the Outlook Signature it. There are quite a bit of information around this on the net but I can't get it to work.
Private Sub cmdEmail_Click()
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String
Dim strHTMLBody As String
'-------------------------------------------------------------------------------------
'The filepath for the attachment is everything to the left of the first # sign delimiter in the hyperlink
'-------------------------------------------------------------------------------------
If Not IsNull(Me.strHyperlink) Then
strFileName = Mid$(Me.strHyperlink, InStr(Me.strHyperlink, "#") + 1)
Else
strFileName = "Empty"
End If
'--------------------------------------------------------------------------------------
'Set the Outlook controls to create a new message
'--------------------------------------------------------------------------------------
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
'--------------------------------------------------------------------------------------
'Set the FROM field
'--------------------------------------------------------------------------------------
OutlookMail.SentOnBehalfOfName = strFrom
'--------------------------------------------------------------------------------------
'Set the TO, CC, BCC fields
'--------------------------------------------------------------------------------------
If Not IsNull(Me.Text96) Then
OutlookMail.To = Me.Text96
End If
If Not IsNull(Me.Text74) Then
OutlookMail.CC = Me.Text74
End If
If Not IsNull(Me.Text91) Then
OutlookMail.CC = OutlookMail.CC & ";" & Me.Text91
End If
If Not IsNull(Me.Text49) Then
OutlookMail.CC = OutlookMail.CC & ";" & Me.Text49
End If
If Not IsNull(Me.Text108) Then
OutlookMail.CC = OutlookMail.CC & ";" & Me.Text108
End If
'--------------------------------------------------------------------------------------
'Set the SUBJECT field
'--------------------------------------------------------------------------------------
OutlookMail.Subject = Me.Text61 & " (" & Me.Text105 & "/" & Me.Text81 & "/" & Me.Text65 & ")"
'--------------------------------------------------------------------------------------
'Set the ATTACHMENT field
'--------------------------------------------------------------------------------------
If strFileName <> "Empty" Then
Set OutlookAttach = OutlookMail.Attachments.Add(strFileName)
End If
'--------------------------------------------------------------------------------------
'Set strHTMLBody
'--------------------------------------------------------------------------------------
strHTMLBody = "<FONT face=Verdana size=2>" & Me.ClaimNote & "<BR>"
strHTMLBody = strHTMLBody & "<BR><BR>Groete/Regards<BR>"
'--------------------------------------------------------------------------------------
'Set the HTMLBODY field
'--------------------------------------------------------------------------------------
OutlookMail.HTMLBody = strHTMLBody & vbCrLf & Signature
'--------------------------------------------------------------------------------------
'Show the message to the user
'--------------------------------------------------------------------------------------
OutlookMail.Display
MsgBox "Email has been send successfully to " & " " & Me.Text96
End Sub
Private Sub cmdEmail_Click()
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String
Dim strHTMLBody As String
'-------------------------------------------------------------------------------------
'The filepath for the attachment is everything to the left of the first # sign delimiter in the hyperlink
'-------------------------------------------------------------------------------------
If Not IsNull(Me.strHyperlink) Then
strFileName = Mid$(Me.strHyperlink, InStr(Me.strHyperlink, "#") + 1)
Else
strFileName = "Empty"
End If
'--------------------------------------------------------------------------------------
'Set the Outlook controls to create a new message
'--------------------------------------------------------------------------------------
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
'--------------------------------------------------------------------------------------
'Set the FROM field
'--------------------------------------------------------------------------------------
OutlookMail.SentOnBehalfOfName = strFrom
'--------------------------------------------------------------------------------------
'Set the TO, CC, BCC fields
'--------------------------------------------------------------------------------------
If Not IsNull(Me.Text96) Then
OutlookMail.To = Me.Text96
End If
If Not IsNull(Me.Text74) Then
OutlookMail.CC = Me.Text74
End If
If Not IsNull(Me.Text91) Then
OutlookMail.CC = OutlookMail.CC & ";" & Me.Text91
End If
If Not IsNull(Me.Text49) Then
OutlookMail.CC = OutlookMail.CC & ";" & Me.Text49
End If
If Not IsNull(Me.Text108) Then
OutlookMail.CC = OutlookMail.CC & ";" & Me.Text108
End If
'--------------------------------------------------------------------------------------
'Set the SUBJECT field
'--------------------------------------------------------------------------------------
OutlookMail.Subject = Me.Text61 & " (" & Me.Text105 & "/" & Me.Text81 & "/" & Me.Text65 & ")"
'--------------------------------------------------------------------------------------
'Set the ATTACHMENT field
'--------------------------------------------------------------------------------------
If strFileName <> "Empty" Then
Set OutlookAttach = OutlookMail.Attachments.Add(strFileName)
End If
'--------------------------------------------------------------------------------------
'Set strHTMLBody
'--------------------------------------------------------------------------------------
strHTMLBody = "<FONT face=Verdana size=2>" & Me.ClaimNote & "<BR>"
strHTMLBody = strHTMLBody & "<BR><BR>Groete/Regards<BR>"
'--------------------------------------------------------------------------------------
'Set the HTMLBODY field
'--------------------------------------------------------------------------------------
OutlookMail.HTMLBody = strHTMLBody & vbCrLf & Signature
'--------------------------------------------------------------------------------------
'Show the message to the user
'--------------------------------------------------------------------------------------
OutlookMail.Display
MsgBox "Email has been send successfully to " & " " & Me.Text96
End Sub