B
Bill
I have a A2003 application compiled and running in a
A2007 environment. The class module for one of the
forms sends an e-mail using the Outlook object model,
(code below). My code runs fine for both Outlook and
Outlook Express while in a 2003 runtime environment,
but in the 2007 runtime environment I get a runtime error
#438: Object doesn't support this property or method.
(I've flagged the statement that caused the error,
Set objOutlookAttach)
I thought at first it might be a reference library issue, but
see that I had long since referenced:
Microsoft Outlook 12.0 Object Library
(Actually, in the 2003 environment the reference shows
as 11.0 and in the 2007 enviroment it shows as 12.0.)
Do I need another reference for the 2007 environment?
Thanks,
Bill
Sub SendMessage(SendTO, SendCOPY, sendBCC, textSubject As String, textBody
As String, _
DisplayMsg As Boolean, Optional AttachmentPath1, Optional
AttachmentPath2, Optional AttachmentPath3)
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(SendTO)
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
If Not IsNull(SendCOPY) Then
Set objOutlookRecip = .Recipients.Add(SendCOPY)
objOutlookRecip.Type = olCC
End If
' Add the BCC recipient(s) to the message.
If Not IsNull(Nz(sendBCC, Null)) Then
Set objOutlookRecip = .Recipients.Add(sendBCC)
objOutlookRecip.Type = olBCC
End If
' Set the Subject, Body, and Importance of the message.
.Subject = textSubject
.Body = textBody & vbCrLf & vbCrLf
' .Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath1) Then
ERROR HERE >>>>> Set objOutlookAttach = .Attachments.Add(AttachmentPath1)
If Not IsMissing(AttachmentPath2) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath2)
If Not IsMissing(AttachmentPath2) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath3)
End If
End If
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
A2007 environment. The class module for one of the
forms sends an e-mail using the Outlook object model,
(code below). My code runs fine for both Outlook and
Outlook Express while in a 2003 runtime environment,
but in the 2007 runtime environment I get a runtime error
#438: Object doesn't support this property or method.
(I've flagged the statement that caused the error,
Set objOutlookAttach)
I thought at first it might be a reference library issue, but
see that I had long since referenced:
Microsoft Outlook 12.0 Object Library
(Actually, in the 2003 environment the reference shows
as 11.0 and in the 2007 enviroment it shows as 12.0.)
Do I need another reference for the 2007 environment?
Thanks,
Bill
Sub SendMessage(SendTO, SendCOPY, sendBCC, textSubject As String, textBody
As String, _
DisplayMsg As Boolean, Optional AttachmentPath1, Optional
AttachmentPath2, Optional AttachmentPath3)
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(SendTO)
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
If Not IsNull(SendCOPY) Then
Set objOutlookRecip = .Recipients.Add(SendCOPY)
objOutlookRecip.Type = olCC
End If
' Add the BCC recipient(s) to the message.
If Not IsNull(Nz(sendBCC, Null)) Then
Set objOutlookRecip = .Recipients.Add(sendBCC)
objOutlookRecip.Type = olBCC
End If
' Set the Subject, Body, and Importance of the message.
.Subject = textSubject
.Body = textBody & vbCrLf & vbCrLf
' .Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath1) Then
ERROR HERE >>>>> Set objOutlookAttach = .Attachments.Add(AttachmentPath1)
If Not IsMissing(AttachmentPath2) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath2)
If Not IsMissing(AttachmentPath2) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath3)
End If
End If
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