User-defined type not defined

P

Pietro

Hi,

Th ebelow code is working fine in a database,i tried to copy and paste it
in my database but it gives me error "User-defined type not defined"



Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.BodyFormat = olFormatHTML
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.mess_text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.add (Me.Mail_Attachment_Path)

End If


'.DeleteAfterSubmit = True 'This would let Outlook send th
note without storing it in your sent bin
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub

email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message
is: " & Err.Description
Resume Error_out
Error_out:
 
D

Douglas J. Steele

What version of Access?

In Access 2003 or earlier, you go into the VB Editor, select Tools |
References from the menu bar and scroll through the list of available
references until you find the reference for Microsoft Outlook x.0 Object
Library (where x will depend on the version of Outlook installed).

In Access 2007, there should be a References option in the ribbon when
you're editting VBA.

Another option would be to use Late Binding. To change your code to use Late
Binding, try:

Const olMailItem As Long = 0
Const olFormatHTML As Long = 2

Dim mess_body As String
Dim appOutLook As Object
Dim MailOutLook As Object

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.BodyFormat = olFormatHTML
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.mess_text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.add (Me.Mail_Attachment_Path)
End If
Send
End With

Exit Sub

This has the advantage that should your users not have the same version of
Outlook to which you set the reference, it'll still work. And if you have a
user who doesn't have any version of Outlook installed, the rest of the
application will still work: only that routine will fail (with an Error 429)
 
P

Pietro

I fixed it through the reference...
thank you...

Douglas J. Steele said:
What version of Access?

In Access 2003 or earlier, you go into the VB Editor, select Tools |
References from the menu bar and scroll through the list of available
references until you find the reference for Microsoft Outlook x.0 Object
Library (where x will depend on the version of Outlook installed).

In Access 2007, there should be a References option in the ribbon when
you're editting VBA.

Another option would be to use Late Binding. To change your code to use Late
Binding, try:

Const olMailItem As Long = 0
Const olFormatHTML As Long = 2

Dim mess_body As String
Dim appOutLook As Object
Dim MailOutLook As Object

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.BodyFormat = olFormatHTML
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.mess_text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.add (Me.Mail_Attachment_Path)
End If
Send
End With

Exit Sub

This has the advantage that should your users not have the same version of
Outlook to which you set the reference, it'll still work. And if you have a
user who doesn't have any version of Outlook installed, the rest of the
application will still work: only that routine will fail (with an Error 429)
 

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

Similar Threads

command to send an e-mail 1
Message body 9
Creating email in Access 1
Compile error? Help! 1
Email from Access 1
try again email forms 1
command button to email form 4
Adding mail.(HTML)body from textbox or table 1

Top