Email problem

P

PsyberFox

Hi there,

I am getting an error stating User-defined type not defined when running the
following code. I have activated References for Microsoft Office 12.0 Object
Library as well as Microsoft Access 12.0 Object Library. This is in Access
2007, and off a command button called cmd_Email

Sub cmd_Email_Click()

Dim objOutlook As Outlook.Application
Dim objOutlookMessage As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMessage
' Add the To recipient(s) to the message.
Set objOutlookRecipient = .Recipients.Add("(e-mail address removed)")
objOutlookRecipient.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecipient = .Recipients.Add("(e-mail address removed)")
objOutlookRecipient.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "Test"
.Body = PropertyRef & vbCrLf _
& PropertyType & vbCrLf _
& PropertyCategory & vbCrLf _
& Description & vbCrLf _
& Address1 & vbCrLf _
& Address2 & vbCrLf _
& Address3 & vbCrLf _
& Active
.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 objOutlookRecipient In .Recipients
objOutlookRecipient.Resolve
If Not objOutlookRecipient.Resolve Then
objOutlookMessage.Display
End If
Next
.Send

End With

Set objOutlookMessage = Nothing
Set objOutlook = Nothing

End Sub

Please help! Thank you very mooch!
 
D

Dirk Goldgar

PsyberFox said:
Hi there,

I am getting an error stating User-defined type not defined when running
the
following code. I have activated References for Microsoft Office 12.0
Object
Library as well as Microsoft Access 12.0 Object Library. This is in Access
2007, and off a command button called cmd_Email

Sub cmd_Email_Click()

Dim objOutlook As Outlook.Application
Dim objOutlookMessage As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

[snip]

Do you have a reference set to the Microsoft Outlook 12.0 Object Library?
You'll need that if you're going to refer to Outlook-defined data types such
as the above.

As an alternative, you could forego the reference and use late binding by
declaring all the Outlook-defined items as Object. You would also have to
declare the constants olMailItem, olTo, olCC, and olImportanceHigh yourself,
since those are defined by the Outlook object library. But if you don't
mind having the reference to the Outlook library, you don't need to do that.
 
P

PsyberFox

Hi,

Yes I do have the reference to that object library, but still gives me the
problem.

Can you possible give me more details on the alternative?

Thank you!
W
--
The Psyber Fox
http://www.psyberconsulting.co.za


Dirk Goldgar said:
PsyberFox said:
Hi there,

I am getting an error stating User-defined type not defined when running
the
following code. I have activated References for Microsoft Office 12.0
Object
Library as well as Microsoft Access 12.0 Object Library. This is in Access
2007, and off a command button called cmd_Email

Sub cmd_Email_Click()

Dim objOutlook As Outlook.Application
Dim objOutlookMessage As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

[snip]

Do you have a reference set to the Microsoft Outlook 12.0 Object Library?
You'll need that if you're going to refer to Outlook-defined data types such
as the above.

As an alternative, you could forego the reference and use late binding by
declaring all the Outlook-defined items as Object. You would also have to
declare the constants olMailItem, olTo, olCC, and olImportanceHigh yourself,
since those are defined by the Outlook object library. But if you don't
mind having the reference to the Outlook library, you don't need to do that.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
P

PsyberFox

Hi again,

I have actually resolved the problem by simply using DoCmd.SendObject, so
not to worry. Thank you in any case!

Rgds,
W

--
The Psyber Fox
http://www.psyberconsulting.co.za


Dirk Goldgar said:
PsyberFox said:
Hi there,

I am getting an error stating User-defined type not defined when running
the
following code. I have activated References for Microsoft Office 12.0
Object
Library as well as Microsoft Access 12.0 Object Library. This is in Access
2007, and off a command button called cmd_Email

Sub cmd_Email_Click()

Dim objOutlook As Outlook.Application
Dim objOutlookMessage As Outlook.MailItem
Dim objOutlookRecipient As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

[snip]

Do you have a reference set to the Microsoft Outlook 12.0 Object Library?
You'll need that if you're going to refer to Outlook-defined data types such
as the above.

As an alternative, you could forego the reference and use late binding by
declaring all the Outlook-defined items as Object. You would also have to
declare the constants olMailItem, olTo, olCC, and olImportanceHigh yourself,
since those are defined by the Outlook object library. But if you don't
mind having the reference to the Outlook library, you don't need to do that.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 

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