Generating an eMail

  • Thread starter Thread starter Stuart B
  • Start date Start date
S

Stuart B

I have been using the following code to generate an email - the code to
generate the email itself works fine per se but when I run it I get a
run-time error on the line:

Dim objOutlook As New Outlook.Application '<< LINE 1
Dim objMessage As MailItem

' strEmailTo is a valid set or email addresses

Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = strEmailTo
.Subject = "Text Subject"
.Body = "Text Detail"
.Send
End With


It says on LINE 1 that the the user defined object is not found. Do I have
to create some other link to Outlook?

Thanks Stuart.
 
I've sent emails from within Access by using the 'SendObject' command. Check
out help for this command, it explains how to do it.
Could be that you've already done this and it doesn't meet your needs. In
which case, sorry to join in

Trevor
 
Stuart,

I suppose there are many ways to tackle this application, but I
go with one that works. The following snippet of code sends an
email via Microsoft Outlook to two recipients, has a subject
line, a body, and an attachment. I use this with Access 2000.
Because of Outlook's security controls, this will bring up a
pop-up window saying "A program is trying to access e-mail
addresses you have stored in Outlook. Do you want to allow
this?" Once you select how many minutes you want to allow
access, the email gets sent. Note: this code was lifted from a
VB6 program that I had written in the past. It worked without
modification when inserted in Access as a subroutine.


Dim EMail As Object
Set EMail = CreateObject("Outlook.Application")
With EMail.CreateItem(olMailItem)
.Recipients.Add "(e-mail address removed)"
.Recipients.Add "(e-mail address removed)"
.Subject = "How To Send EMail"
.Body = "This small piece of code is an example of sending
email"
.Attachments.Add "C:\Temp\MyFile.doc"
.Send
End With

Roger


-----------------------------------


"Stuart B" <SHB> wrote in message
I have been using the following code to generate an email - the
code to
generate the email itself works fine per se but when I run it I
get a
run-time error on the line:

Dim objOutlook As New Outlook.Application '<< LINE 1
Dim objMessage As MailItem

' strEmailTo is a valid set or email addresses

Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = strEmailTo
.Subject = "Text Subject"
.Body = "Text Detail"
.Send
End With


It says on LINE 1 that the the user defined object is not found.
Do I have
to create some other link to Outlook?

Thanks Stuart.
 
Back
Top