From: PsyberFox on
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("koenwk(a)mweb.co.za")
objOutlookRecipient.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecipient = .Recipients.Add("koenwk(a)mweb.co.za")
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!

--
The Psyber Fox
http://www.psyberconsulting.co.za
From: Dirk Goldgar on
"PsyberFox" <PsyberFox(a)discussions.microsoft.com> wrote in message
news:C6C40830-6F8D-4EA2-8EE1-7199F6A3998B(a)microsoft.com...
> 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)

From: PsyberFox on
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" wrote:

> "PsyberFox" <PsyberFox(a)discussions.microsoft.com> wrote in message
> news:C6C40830-6F8D-4EA2-8EE1-7199F6A3998B(a)microsoft.com...
> > 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)
>
From: PsyberFox on
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" wrote:

> "PsyberFox" <PsyberFox(a)discussions.microsoft.com> wrote in message
> news:C6C40830-6F8D-4EA2-8EE1-7199F6A3998B(a)microsoft.com...
> > 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)
>