User-defined type not defined???

S

Steven M. Britton

I have a mod that I use all the time in one of my
databases I imported it into another database to use and
now when I call it it says User-defined type not defined.

It points to the "Dims" at that top of the code, if I
remove all of the Dims it will run the code, but doesn't
function properly. I don't understand why it works for
one database and not the other when it is the excat same
code????
-Steve

Sub SendMessageHeathlyTips(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

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

' Set the Subject, Body, and Importance of the
message.
.Subject = "Daily Shipment File"
.Body = "Here is the file you requested." & vbCrLf &
vbCrLf
.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 objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 
G

Gerald Stanley

The likeliest explanation is that the database into which
you imported the module doe not have the neccesary
reference to the Outlook Object Library.

In the VB Editor, go to Tools->References and ensure that
the Outlook object library is ticked.

Hope This Helps
Gerald Stanley MCSD
 

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