I've written a function to check emails in Outlook using Access which
works. But I need to be able to have it work for different version of
Outlook. I'm using Outlook 2002 and I need to also work for Outlook
2000. I don't want the user to go and find the reference file in
Access. So I need this code to work for all versions. I think I need
to use late binding but don't know anything about it.
Here is the function:
Dim OlkApp As Outlook.Application
Dim OlkMapi As Outlook.NameSpace
Dim OlkFolder As Outlook.MAPIFolder
Dim olkSubFolder As Outlook.MAPIFolder
Dim OlkReadFolder As Outlook.MAPIFolder
Dim OlkItems As Outlook.Items
Dim OlkMail As Object
Dim cnn As New ADODB.Connection
On Error GoTo GetEmailData_Error
DoCmd.Hourglass True
Set cnn = CurrentProject.Connection
' Delete existing records in the ImportData table
strSQL = "DELETE * FROM ImportData"
cnn.Execute strSQL
' Create Outlook connection
Set OlkApp = CreateObject("Outlook.Application")
Set OlkMapi = OlkApp.GetNamespace("MAPI")
' Define folders
Set OlkFolder = OlkMapi.GetDefaultFolder(olFolderInbox)
Set OlkReadFolder = OlkFolder.Folders("FEEDBACK")
Set OlkMoveFolder = OlkFolder.Folders("Feedback ARCHIVE")
' Find the Feedback Outlook folder (subfolder of Inbox folder)
For Each olkSubFolder In OlkFolder.Folders
If olkSubFolder.Name = "FEEDBACK" Then
Set OlkItems = olkSubFolder.Items
If OlkItems.Count > 0 Then
Call AddEmailData(olkSubFolder)
End If
Exit For
End If
Next
MsgBox "Finished Importing Outlook Email Data.", vbInformation,
"Outlook Data Import"
GetEmailData_Exit:
Set OlkApp = Nothing
Set OlkMapi = Nothing
Set OlkFolder = Nothing
Set OlkReadFolder = Nothing
Set OlkMoveFolder = Nothing
Set OlkItems = Nothing
DoCmd.Hourglass False
Exit Function
GetEmailData_Error:
MsgBox Err.Description, vbInformation, "Get Email Data"
Resume GetEmailData_Exit
So I would like to know how to change this to code to late binding.
Any help would be appreciated.