Solved

Retrieving emails from Outlook using Access 2010 vba and Late Binding

Posted on 2013-05-16
11
752 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 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

20 Experts available now in Live!

Get 1:1 Help Now