Solved

Retrieving emails from Outlook using Access 2010 vba and Late Binding

Posted on 2013-05-16
11
801 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 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access, How to create variable 9 38
Access - Question on concatenation of field values 3 32
MS Access, hourly employee status 8 43
Clear Current Value from Combobox 2 26
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 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