Auto-enter a Subject in an Email Generated by Access

G

Guest

I am trying to write code that will automatically enter the contents of a
control (called Identifier) on my form when a user clicks a button on the
form. Currently, the button is "powered" by a macro using the SendObject
command. I've found information by Tony Towes and Arvin Meyer, but so far I
can't get the code to work. (Error message is described below.)

I took the Click event of the button that ran the "SendMail" macro and
substituted the following:

Private Sub cmdSend_Click()
On Error GoTo Err_cmdSend_Click

Dim objOutlook As Outlook.Application
Dim ojbEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
SetobjEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.Subject = Me!Identifier

End With


Exit_cmdSend_Click:
Exit Sub

Err_cmdSend_Click:
MsgBox Err.Description
Resume Exit_cmdSend_Click

End Sub

Here's the error: "User-defined type not defined" and what is highlighted
is " Dim objOutlook As Outlook.Application". Can anyone point out what I'm
doing wrong -- or point to another way of auto-entering info into a Subject
line? Thanks!
 
G

Graham Mandeno

Hi Susan

The problem is that if you want to declare Outlook objects in your code, you
have to add a reference to the Outlook Object Library.

Go to Tools>References and find "Microsoft Outlook x.x Object Library" in
the list (where x.x is your version number) and check it. Then your code
should compile OK.

Alternatively, you can use what is known as "late binding". This has
advantages in that your code will continue to run whatever version of
Outlook is installed. To do this, declare objOutlook and objEmail "As
Object", instead of "As Outlook.xxx".
 

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