Using VBA within Access, I'm trying to reply to an email with a template. The code follows and it creates and displays the email that I want.
However, it doesn't show the SEND button on the email.
The subroutine performs a .display to show the email. Do I need to use a different command?
' Email Response
'
' Parameters
' Template for reply
' Email Box to find Email
' Email Address to Respond
Sub srtnGenerateReply(ByVal sTemplateText As String, ByVal sEmailMailBox As String, ByVal sEmailAddress As String)
Dim OutlookApp As outlook.Application
Dim OutlookNamespace As outlook.NameSpace
Dim olShareName As outlook.Recipient
Dim Folder As MAPIFolder
Dim olItems As outlook.Items
Dim OutlookMail As Variant
Dim arrResults() As Variant
Dim ItemCount As Long
Dim sFilter As String
sFilter = "[SenderEmailAddress] = '" & sEmailAddress & "'"
Set OutlookApp = New outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set olShareName = OutlookNamespace.CreateRecipient(sEmailMailBox)
Set Folder = OutlookNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox)
Set olItems = Folder.Items.Restrict(sFilter)
' sort to get the most recent email for the Email Address to respond
olItems.Sort "[ReceivedTime]", True
If olItems.Count < 1 Then
MsgBox ("No Email Found")
End If
For Each OutlookMail In olItems
OutlookMail.ReplyAll
OutlookMail.HTMLBody = sTemplateText & _
" <hr> <br/>" & _
"<b>From: </b>" & OutlookMail.SenderName & " [" & OutlookMail.SenderEmailAddress & "]<br/>" & _
"<b>Sent: </b>" & OutlookMail.SentOn & "<br/>" & _
"<b>To: </b>" & OutlookMail.To & "<br/>" & _
"<b>Subject: </b>" & OutlookMail.Subject & "<br/>" & _
"<br/>" & _
OutlookMail.HTMLBody\
OutlookMail.Display
Exit For ' Exit -- Only reply to lastest email
Next OutlookMail
Set OutlookApp = Nothing
Set OutlookNamespace = Nothing
End Sub
However, it doesn't show the SEND button on the email.
The subroutine performs a .display to show the email. Do I need to use a different command?
' Email Response
'
' Parameters
' Template for reply
' Email Box to find Email
' Email Address to Respond
Sub srtnGenerateReply(ByVal sTemplateText As String, ByVal sEmailMailBox As String, ByVal sEmailAddress As String)
Dim OutlookApp As outlook.Application
Dim OutlookNamespace As outlook.NameSpace
Dim olShareName As outlook.Recipient
Dim Folder As MAPIFolder
Dim olItems As outlook.Items
Dim OutlookMail As Variant
Dim arrResults() As Variant
Dim ItemCount As Long
Dim sFilter As String
sFilter = "[SenderEmailAddress] = '" & sEmailAddress & "'"
Set OutlookApp = New outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set olShareName = OutlookNamespace.CreateRecipient(sEmailMailBox)
Set Folder = OutlookNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox)
Set olItems = Folder.Items.Restrict(sFilter)
' sort to get the most recent email for the Email Address to respond
olItems.Sort "[ReceivedTime]", True
If olItems.Count < 1 Then
MsgBox ("No Email Found")
End If
For Each OutlookMail In olItems
OutlookMail.ReplyAll
OutlookMail.HTMLBody = sTemplateText & _
" <hr> <br/>" & _
"<b>From: </b>" & OutlookMail.SenderName & " [" & OutlookMail.SenderEmailAddress & "]<br/>" & _
"<b>Sent: </b>" & OutlookMail.SentOn & "<br/>" & _
"<b>To: </b>" & OutlookMail.To & "<br/>" & _
"<b>Subject: </b>" & OutlookMail.Subject & "<br/>" & _
"<br/>" & _
OutlookMail.HTMLBody\
OutlookMail.Display
Exit For ' Exit -- Only reply to lastest email
Next OutlookMail
Set OutlookApp = Nothing
Set OutlookNamespace = Nothing
End Sub