?
Solved

Retrieving emails from Outlook using Access 2010 vba and Late Binding

Posted on 2013-05-16
11
Medium Priority
?
832 Views
Last Modified: 2013-05-30
I am using late binding in retrieving emails from Outlook. Therefore, I am not checking the Microsoft Outlook 14.0 Object Library reference within Tools-References.

I am using the following code to retrieve emails from Folder B:
dim objOutlook as Object
dim OutlookNameSpace as Object
dim Inbox as Object

set objOutlook = GetObject (, "Outlook.application")
set OutlookNameSpace = objOutlook.GetNamespace("MAPI")

set Inbox = OutlookNameSpace.GetDefaultFolder(6).Folders("A").Folders("B")

This code works correctly. Now, I need to retrieve emails from a folder, which is not the Default Inbox folder. Prior to using late binding, I was using the following statement to retrieve these emails:

set Inbox = objOutlook.GetNamespace("Mapi").Folders("Mailbox - DDD").Folders("Inbox").Folders("New Entries")

How is the above statement used with late binding?
0
Comment
Question by:newbie46
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 58
ID: 39171481
<<How is the above statement used with late binding? >>

 Should be the same.

Jim.
0
 

Author Comment

by:newbie46
ID: 39171533
Jim,
I get an error when using:

set Inbox = OutlookNameSpace.Folders("Mailbox - DDD").Folders("Inbox").Folders("New Entries")

I am not at work today, so cannot provide the exact message.

Similar to using GetDefaultFolder(6) when accessing the default Inbox folder, is there another statement needed when accessing an Inbox folder which is not the default inbox folder?
0
 

Author Comment

by:newbie46
ID: 39171567
Jim,
From a post that I just found via the internet, it looks as though the statement would be:

set Inbox = OutlookNameSpace.GetDefaultFolder(6).Folders("Mailbox - DDD").Folders("Inbox").Folders("New Entries")

Does this look correct? Since I am not in the office, I cannot test this to verify.

Thanks.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 58
ID: 39171582
That should be it.  Error would be helpful.

Jim.
0
 
LVL 58
ID: 39171592
<<set Inbox = OutlookNameSpace.GetDefaultFolder(6).Folders("Mailbox - DDD").Folders("Inbox").Folders("New Entries")>>

 Where is mailbox -DDD?  Is it within the Inbox folder?

Jim.
0
 

Author Comment

by:newbie46
ID: 39171599
Jim,

The posting at http://www.slipstick.com/outlook-developer/working-vba-nondefault-outlook-folders/ states the following:

To use a folder at the same level as the Default folders (such as Calendar, Inbox etc), use this in place of Set Items = Ns.GetDefaultFolder(olFolderCalendar).Items, where SharedCal is the folder name:

Set Items = Session.GetDefaultFolder(olFolderCalendar).Parent.Folders("SharedCal").Items
 
-----------------------------------------------

Therefore, would Session be needed, as in the following statement?
set Inbox = Session.GetDefaultFolder(6).Folders("Mailbox - DDD").Folders("Inbox").Folders("New Entries")
0
 

Author Comment

by:newbie46
ID: 39171607
Jim,
No, DDD is not within the mailbox folder. Mailbox - DDD is shared inbox.
0
 

Author Comment

by:newbie46
ID: 39171641
Sorry. DDD is not within the Inbox folder. Mailbox - DDD is a shared mailbox that multiple people can access. Within this Mailbox - DDD is an Inbox folder, which is then synonymous in terms of levels to the default Inbox folder on each person's machine.
0
 

Author Comment

by:newbie46
ID: 39188096
Jim,
Any ideas?
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 39188452
Sorry I missed you comment.

 I would put a STOP right above this:

set Inbox = OutlookNameSpace.Folders("Mailbox - DDD").Folders("Inbox").Folders("New Entries")

 Execute and then from the debug window, you can feel your way through the objects at that point.  ie.

 ?  OutlookNameSpace.Folders(0).Name  

 would give you the name of the first

OutlookNameSpace.Folders(1).Name

 Would give you the name of the second and so on.  WIthin a few minutes, you should be able to determine the objects you need to reference to get to the mail folder you want.

Jim.
0
 

Author Comment

by:newbie46
ID: 39207319
Jim,
Sorry for the delay. I finally had the chance to try this at the office and was able to find the folder using the above suggestion.

Thank you!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question