By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

Outlook Late Binding

P: n/a
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.

Apr 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Ecohouse" <vi*******@netzero.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
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
For late binding, replace the above line with this:
Dim OlkApp as Object
(and do the same thing for the following lines:)
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


Apr 3 '06 #2

P: n/a
Also, you will have to replace the named constants
(olFolderInbox etc) with true values.

[Ctrl][G} to go to the immediate window, then
?olFolderInbox
to see the value.

do this before you remove the Outlook reference.

Fortunately, these named values have not changed.

(david)
"Ecohouse" <vi*******@netzero.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
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.

Apr 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.