Solved

How can I search OutlooknameSpace.Folders to find the needed Shared Mailbox using VBA?

Posted on 2013-06-26
3
662 Views
Last Modified: 2013-07-02
I am importing emails from Outlook 2010 using Access 2010. The emails are imported from a Shared mailbox ABC. Each user of the database has differing numbers of mailboxes on their machines. Thus, the Shared mailbox ABC may be accessed via:
Set Inbox = OutlookNameSpace.Folders(3).Folders("Inbox").Folders("New Entries") within one user's machine and may be accessed via:
Set Inbox = OutlookNameSpace.Folders(4).Folders("Inbox").Folders("New Entries")  within another user's machine.

I am looking for a way to search through the OutlookNameSpace.Folders using VBA to find the correct Shared mailbox ABC. When I use the following code, the error is trapped the first time and execution returns to FindMailboxFolder. If the folder is not found the 2nd time through, the error is no longer trapped within the code. Instead an error is displayed and processing within VBA is halted.

How can I search through OutlookNameSpace.folder dynamically in order to find the Shared mailbox on each user's machine?

Dim objOutlook As Object    'Outlook.Application
Dim OutlookNameSpace As Object
dim MailboxFolderNumber as Integer

On Error GoTo Err_ImportEmails_Click

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

MailboxFolderNumber = 3

FindMailboxFolder:
Set Inbox = OutlookNameSpace.Folders(MailboxFolderNumber).Folders("Inbox").Folders("New Entries")  
.
.
.
Exit_ImportEmails_Click:
  Set objOutlook = Nothing
  Set OutlookNameSpace = Nothing
  Exit Sub
  
Err_ImportEmails_Click:
  If Err.Number = -2147221233 Then
    MailboxFolderNumber = MailboxFolderNumber + 1
    GoTo FindMailboxFolder
  Else
   MsgBox Err.Number & vbCrLf & Err.Description, , "ImportEmails_Click"
  End If
 Resume Exit_ImportEmails_Click

Open in new window

0
Comment
Question by:newbie46
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
Comment Utility
Is there a reason you cannot simply use the name?

OutlookNameSpace.Folders("ABC") i.e.

OutlookNameSpace.Folders("ABC").Folders("Inbox").Folders("New Entries")

Chris
0
 

Author Closing Comment

by:newbie46
Comment Utility
This worked. Thank you!!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

10 Experts available now in Live!

Get 1:1 Help Now