Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-06-26
3
Medium Priority
?
828 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
2 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

773 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