Getting to a Public Folder through VBA in 2010

Posted on 2011-05-12
Last Modified: 2012-05-11
I am trying to access a public folder for an email process But I cant seem to get there.

Here is my code:

 Dim ol As New Outlook.Application
    Dim olns As Outlook.NameSpace
    Dim mf As Outlook.MAPIFolder
    Dim destf As Outlook.MAPIFolder
    Dim m As Outlook.Items
    Dim objItem As Object
    Dim mailItem As mailItem
    Dim numitems As Integer
    Dim destfolder As String
    Dim i As Integer

Set olns = ol.GetNamespace("MAPI")
    Set mf = olns.GetDefaultFolder(olPublicFolderContacts).[All Public Folders].Company.Dept..[Job Emails]
    Set destf = olns.GetDefaultFolder(olFolderInbox).Folders("Test2")
    Set errf = olns.GetDefaultFolder(olFolderInbox).Folders("Error No @")
    Set errf2 = olns.GetDefaultFolder(olFolderInbox).Folders("Error Bad Job")

I get an error: "one or more parameter values are not valid"
Question by:mjelec
    LVL 59

    Expert Comment

    by:Chris Bottomley
    Have you used the folders parameter:

    Set mf = olns.GetDefaultFolder(olPublicFolderContacts).[All Public Folders].Company.Dept..[Job Emails]
    Set mf = olns.GetDefaultFolder(olPublicFolderContacts).folders("All Public Folders").folders("Company").folders("Dept").folders("Job Emails")


    Author Comment

    When I try that I get:

    Microsoft Access cant find the field '|1' referred to in your expression.

    should it be: olPublicFolders rather then olPublicFolderContact?
    LVL 59

    Accepted Solution

    Sorry I don't have access to a public folder these days so I was taking something of a lead from you.  In my previous experience the public folders were accessed by olPublicFoldersAllPublicFolders.  I have therefore made an assumption re the path but basically for each level of folders below the public level drop a folders("nam") structure in place and it ought to be ok.

    olns.GetDefaultFolder(olPublicFoldersAllPublicFolders).folders("contacts").folders("All Public Folders").folders("Company").folders("Dept").folders("Job Emails")


    Author Closing Comment

    That worked, I think I was also wrong with my first attempt I had []'s around values with spaces

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
    Use email signature images to promote corporate certifications and industry awards.
    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 …
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    733 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

    23 Experts available now in Live!

    Get 1:1 Help Now