Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2106
  • Last Modified:

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"
0
mjelec
Asked:
mjelec
  • 2
  • 2
1 Solution
 
Chris BottomleyCommented:
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
0
 
mjelecAuthor Commented:
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?
0
 
Chris BottomleyCommented:
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")

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now