VBA Error when linking Access to Outlook

  • Thread starter Thread starter ChuckW
  • Start date Start date
C

ChuckW

Hi,

I have an Access application that is designed to send off
e-mails through outlook to people using some VBA code
which I don't know very well. The application is
designed to be able to install it on any Windows XP
machine with Access and Outlook and work correctly which
it has for 2-3 other PCs. However, when I installed it
on another XP machine that had Outlook and Access I got
an error message that said "Run Time Error 438. Object
doesn't support this property or method." When I click
on the debug window, it takes me to a line of VBA code
that says "SetLocationConnection=
CurrentProject.AccessConnection".

Any idea what is causing this error?

Thanks,

Chuck
 
Try this

Sub SendMessage(DisplayMsg As Boolean, 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("Nancy
Davolio")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Michael
Suyama")
objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.

Set objOutlookRecip = .Recipients.Add("Andrew
Fuller")
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the
message.
.Subject = "This is an Automation test with
Microsoft Outlook"
.Body = "This is the body of the message." &
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
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Send
End If

End With
Set objOutlook = Nothing
End Sub
 
Thanks for your help. I am a bit of a VBA novice. Where
would I load this VBA program? Would I tie it to a
specific object? Right now I have command buttons on a
Form. The command buttons have VBA code in them that
opens outlook and sends certain people e-mails to remind
them about upcoming appointments they have with the
clinic. The text of the e-mail is tied to certain fields
in my query that will list the doctors name, the
treatment and the schedule time of their next
appointment. This program has worked fine at two of our
clinics but when I installed it at a third clinic I am
getting the error message:

"Run Time Error 438. Object
 
Back
Top