Solved

Retrieving emails from Outlook using Access 2010 vba and Late Binding

Posted on 2013-05-16
11
773 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
  • 7
  • 4
11 Comments
 
LVL 57
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
 
LVL 57
ID: 39171582
That should be it.  Error would be helpful.

Jim.
0
 
LVL 57
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now