public folders

G

Guest

I am using VBA in Access 2003 and would like to edit Contacts in the Public
Folders. The code works fine for the Default Contacts, but when accessing
Contacts with in the Public Folders it fails. It appears the object, item,
is a 'Post' item instead of a 'Contact' item.

Thanks in advance...

Jack
 
S

Sue Mosher [MVP-Outlook]

What code? What indication do you have that it's a PostItem?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

apple said:
I am using VBA in Access 2003 and would like to edit Contacts in the Public
Folders. The code works fine for the Default Contacts, but when accessing
Contacts with in the Public Folders it fails. It appears the object, item,
is a 'Post' item instead of a 'Contact' item.

Thanks in advance...

Jack

I am checking the item class. When it works the class is '40' which is a
Contact item. In this case when it does not work the class is '45' which is
a Post item.
 
S

Sue Mosher [MVP-Outlook]

So, did you look at the actual item? Maybe the folder really does contain a stray PostItem.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

The items in the Contact look normal. This problem seems to also occur in
any Contact Folder that is a Sub-Folder. I quess my question is: Is it
possible to edit Contacts in sub-folders, public folders, and sub-folders
within public folders using VBA code?
 
S

Sue Mosher [MVP-Outlook]

Is it
possible to edit Contacts in sub-folders, public folders, and sub-folders
within public folders using VBA code?

Certainly, as long as the current user has the appropriate permission on the folder. Maybe it's time you showed a code snippet?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Sue, here is the code:
Option Compare Database

Function FixOutlookContactsjfl()
Dim MyFolder As Outlook.MAPIFolder
Dim MyItems As Outlook.Items
Dim MyItem As Object


'Set MyFolder =
Outlook.Application.GetNamespace("MAPI").Folders("Mailbox - Neel
Sus").Folders("SageCRM")
'Set MyFolder = Outlook.Application.GetNamespace("MAPI").Folders("Public
Folders").Folders("All Public Folders").Folders("TheOlingerGroup Contacts")
Set MyFolder =
Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
'Set MyFolder = Outlook.Application.GetNamespace("MAPI").PickFolder

MsgBox "MyFolder: " & " " & str(MyFolder.Class)
Set MyItems = MyFolder.Items

'If MyItems.Class = olItemProperties Then
'MsgBox "TEST" & " - " '& MyItem.FirstName
'End If
MsgBox "MyItems: " & " " & str(MyItems.Class)


i = MyItems.Count
For Each MyItem In MyItems
MsgBox "MyItem: " & " " & str(MyItem.Class)


'If Len(MyItem.Email1Address) = 0 Then
'Else
MyItem.Email1DisplayName = MyItem.FirstName & " " & MyItem.LastName
& " (" & MyItem.Email1Address & ")"


'MyItem.Save
End

'End If
Next

Set MyItem = Nothing
Set MyItems = Nothing
Set MyFolder = Nothing

End Function
 
S

Sue Mosher [MVP-Outlook]

Taking out all the comments, below is what I get. myItem.Save was commented out.

Set MyFolder = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
Set MyItems = MyFolder.Items
For Each MyItem In MyItems
MsgBox "MyItem: " & " " & str(MyItem.Class)
MyItem.Email1DisplayName = MyItem.FirstName & " " & MyItem.LastName & " (" & MyItem.Email1Address & ")"
End
Next

The right way to iterate a contacts folder needs to involve a more robust check for Class:

On Error Resume Next
For Each MyItem in MyItems
If myItem.Class = olContact Then
MyItem.Email1DisplayName = MyItem.FirstName & " " & MyItem.LastName & " (" & MyItem.Email1Address & ")"
MyItem.Save
End If
Next

Even if an item "looks normal," it still could be a PostItem if the custom form was designed to look like a contact.


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top