Sendiing Emails through Access 2000

C

ChrisBat

Hi,

What I'm trying to do is build a form that will allow me
to link directly with Outlook. Below is the code that I
took from the Microsoft paper How to Use Automation to
Send a Microsoft Outlook Message Using Access 2000 (ID
209948). The code works splendidly, except for two small
glitches. (1) The code only seems to work testing it from
the immediate window. This just won't do. (2) I want the
information to be taken using a form, with the recipient,
subject and body to be text boxes; Importance to default
to Normal (I figured out this part); and Send and Attach
to be buttons, with the Attach button opening the Attach
Which File window. Does anybody have any ideas? I'm
running Access 2000 on a Windows NT 4.0 machine.
Thank you very, very much.
Chris

Option Compare Database
Option Explicit

Sub SendMessage(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 reciepient(s) to the message
Set objOutlookRecip = .Recipients.Add("_____@____.com")
objOutlookRecip = .Type = olTo

' Add the CC recipient(s) to the message
Set objOutlookRecip = .Recipients.Add("_____@____.com")
objOutlookRecip = .Type = olCC

' Set the subject, body and importance of the message
.Subject = "_____________"
.Body = "_______________________"
.Importance = olImportanceNormal

' 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
If Not objOutlookRecip.Resolve Then
objOUtlookMsg.Display
End If
Next
.Send

End With
Set objOUtlookMsg = Nothing
Set objOutlook = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top