raystownlaura
Registered User.
- Local time
- Today, 02:05
- Joined
- Apr 16, 2010
- Messages
- 22
I'm using late binding vba code to send an automated email. The reason is that 2 of us use Access and Outlook 2007 and the other 2 use Access/Outlook 2003. Therefore when the database is opened on a 2003 machine, the reference to Outlook 12.0 Object Library gets broken.
We are a non-profit organization and have to work with what we have. We don't have the budget to upgrade all of us to Office 2007 so late binding is my only option.
I have never worked with late binding, so I would appreciate any help I can get to fix this code. It is erroring out telling me "Method or data member not found" when it gets to the following lines of code:
The complete function is:
Please remember, this is my only option since we are on a non-profit budget - we cannot upgrade two of our folks to Office 2007 so I must use late binding code.
Any help at all is greatly appreciated.
THANKS!!!
We are a non-profit organization and have to work with what we have. We don't have the budget to upgrade all of us to Office 2007 so late binding is my only option.
I have never worked with late binding, so I would appreciate any help I can get to fix this code. It is erroring out telling me "Method or data member not found" when it gets to the following lines of code:
Code:
Set MAPISession = Outlook.NameSpace
Set MAPIFolder = Outlook.MAPIFolder
Set MAPIMailItem = Outlook.mailItem
Set oRecipient = Outlook.Recipient
The complete function is:
Code:
Public Sub RequestInvoice(ByVal EmailBody As String)
On Error GoTo ErrHandle
Const oMailItem As Long = 0
Dim oOutlook As Object
Dim emailItem As Object
Dim MAPISession As NameSpace
Dim MAPIFolder As MAPIFolder
Dim MAPIMailItem As Object
Dim oRecipient As Object
Set oOutlook = CreateObject("Outlook.Application")
Set emailItem = oOutlook.CreateItem(olMailItem)
[B]'CODE HANGS UP HERE WITH "METHOD OR DATA MEMBER NOT FOUND" ERROR[/B]
Set MAPISession = Outlook.NameSpace
Set MAPIFolder = Outlook.MAPIFolder
Set MAPIMailItem = Outlook.mailItem
Set oRecipient = Outlook.Recipient
'Get the MAPI NameSpace object
Set MAPISession = Application.Session
If Not MAPISession Is Nothing Then
'Logon to the MAPI session
MAPISession.Logon , , True, False
'Create a pointer to the Outbox folder
Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderOutbox)
If Not MAPIFolder Is Nothing Then
'Create a new mail item in the "Outbox" folder
Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
If Not MAPIMailItem Is Nothing Then
With MAPIMailItem
Set oRecipient = .Recipients.Add("vsmith@raystown.org")
oRecipient.Type = olTo
Set oRecipient = Nothing
Set oRecipient = .Recipients.Add("estoddard@raystown.org")
oRecipient.Type = olCC
Set oRecipient = Nothing
.Subject = "Invoice Request"
.Body = EmailBody
.Save
.Send
End With
End If
End If
End If
Set MAPIMailItem = Nothing
Set MAPIFolder = Nothing
MAPISession.Logoff
Set MAPISession = Nothing
Set oOutlook = Nothing
Exit_ErrHandle:
Exit Sub
ErrHandle:
MsgBox "An error occurred in 'RequestInvoice' function." & vbCr & vbCr _
& "Please provide the following information " & vbCrLf & "to the database administrator: " & vbCr & vbCr & "Error # " & Err.Number & ": " & Err.Description, vbCritical, "Error: " & Err.Number
Resume Exit_ErrHandle
End Sub
Please remember, this is my only option since we are on a non-profit budget - we cannot upgrade two of our folks to Office 2007 so I must use late binding code.
Any help at all is greatly appreciated.
THANKS!!!