G
Guest
Hi,
I have some code that I got from Microsoft that I can use to send an
automatic email from access - this code is iserted into a module and is
called from a sub.
I would like the module when it is called by the sub, to pick up some of the
fields from a form and then email the details out.
So to summarise, I click a button on my form, it executes VBA code which
calls the module.
How do I get the module to pick up the contents of these fields so that it
can be emailed?
In the code below, the subject line contains the fileds that I would like to
display from the form (ie. "**RECALL** - **NO ** - ** CDE ** - ** NO **")
The code that I got from the MS website is as follows:
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Bill Gates")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Admin")
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
'Set objOutlookRecip = .Recipients.Add("")
'objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = "**RECALL** - **NO ** - ** CDE ** - ** NO **"
.Body = "Blah Blah Blah"
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
I have some code that I got from Microsoft that I can use to send an
automatic email from access - this code is iserted into a module and is
called from a sub.
I would like the module when it is called by the sub, to pick up some of the
fields from a form and then email the details out.
So to summarise, I click a button on my form, it executes VBA code which
calls the module.
How do I get the module to pick up the contents of these fields so that it
can be emailed?
In the code below, the subject line contains the fileds that I would like to
display from the form (ie. "**RECALL** - **NO ** - ** CDE ** - ** NO **")
The code that I got from the MS website is as follows:
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Bill Gates")
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Admin")
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
'Set objOutlookRecip = .Recipients.Add("")
'objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = "**RECALL** - **NO ** - ** CDE ** - ** NO **"
.Body = "Blah Blah Blah"
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub