Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-26
3
Medium Priority
?
796 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
[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
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 39280524
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
ID: 39294578
This worked. Thank you!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

688 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