Solved

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

Posted on 2013-06-26
3
678 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
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HasData 9 37
Outlook keeps opened file locked 2 56
Enabling remote mailbox for existing user 4 36
append to an ms access field 6 26
Outlook Free & Paid Tools
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
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…
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 …

867 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

25 Experts available now in Live!

Get 1:1 Help Now