|
|
Question : Microsoft Access Open Email Message (Outlook) and populate it with data from the database!
|
|
Microsoft Access Open Email Message (Outlook) and populate it with data from the database! I need to be able to open an outlook email message and populate it from a button click, I know that I can do this with a macro like this and then call the macro, however, the macro will not take the length that I need to put in the email message. Here is the macro AnyName Action: SendObject CC: ="[" & [Opened By E-Mail] & "]" & "; [" & [Assigned To E-Mail] & "]" Subject: ="New Task: **SUSPENSE** " & [DueDate] & " **TITLE**: " & [Title] Message Text:= "SUSPENSE:" & [DueDate] & Chr(13) & Chr(10) & "ACTION:" & Chr(13) & Chr(10) & [Comment] & Chr(13) & Chr(10) & "BACKGROUND:" & Chr(13) & Chr(10) & [Background] & Chr(13) & Chr(10) & "SPECIAL INSTRUCTIONS:" & Chr(13) & Chr(10) & [Special_Instr] Edit Message:Yes The problem is I need to add a lot more in message text and doing it the macro way wont cut it this time. Thanks in advance!
|
Answer : Microsoft Access Open Email Message (Outlook) and populate it with data from the database!
|
|
You'll need to add a reference to the Outlook object library
Public Function SendMessage_Test() 'On Error Resume Next
'declare and open instance of MS Outlook Dim olOutlook As New Outlook.Application Dim olOutlookMsg As Outlook.MailItem Dim olOutlookRecip As Outlook.Recipient Dim olOutlookAttach As Outlook.Attachment Dim olInspector Dim strMsgBody As String, strAttachmentName As String Dim strRecipList As String, strAttachmentPath As String Dim strSubject As String
Dim blDisplayMsg As Boolean, blAttachment As Boolean 'configuration-------------------------------------------- 'attachments 'blAttachment = True 'include attachment blAttachment = False 'don't include attachment 'assign attachment path to string variable strAttachmentPath = "C:\OM Gang\Attachments\" 'assign name of attachment to string variable 'strAttachmentName = "MyAttachment.pdf" 'message subject strSubject = "This is the subject" 'display message option 'blDisplayMsg = True 'display message before sending blDisplayMsg = False 'don't display 'assign name table or query containing the recipient list strRecipList = "[email protected]" 'end configuration----------------------------------------
'build message body strMsgBody = "build your message body here" Set olOutlookMsg = olOutlook.CreateItem(olMailItem) Set olInspector = olOutlookMsg.GetInspector
With olOutlookMsg 'recipient Set olOutlookRecip = .Recipients.Add(strRecipList) olOutlookRecip.Type = olTo
'subject, body, importance .Subject = strSubject .Body = strMsgBody .Importance = olImportanceNormal
'attachment? If blAttachment = True Then Set olOutlookAttach = .Attachments.Add(strAttachmentPath _ & strAttachmentName, , , strAttachmentName) End If
'display before sending? If blDisplayMsg = True Then .Display Else .Save .Send End If
End With Exit_SendMessage_Test: 'clear object variables Set olOutlookAttach = Nothing Set olOutlookRecip = Nothing Set olOutlookMsg = Nothing Set olOutlook = Nothing Exit Function
End Function
|
|
|
|
|