Link to home
Start Free TrialLog in
Avatar of mjelec
mjelec

asked on

Getting to a Public Folder through VBA in 2010

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"
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you used the folders parameter:

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

Chris
Avatar of mjelec
mjelec

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mjelec

ASKER

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