I am working with this little subroutine that will enumerate certain properties of items in an Outlook Contact Folder, but it's throwing a type mismatch on a certain iteration of a For...Next loop everytime, and I have no idea why. See comments. Here's the subroutine:
Code:
Sub EnumFolders()
'Taken From pg 644 of Programming MS Access 2002 -Rick Dobson
'Will run as a module from within Outlook itself or Access
Dim myOlApp As Outlook.Application
Dim myNameSpace As NameSpace
Dim myFolders As Outlook.Folders
Dim myFolder As Outlook.MAPIFolder
Dim myContact As Outlook.ContactItem
Dim i As Integer
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders.Item(1).Folders
i = 0
'Enumerate folders
For Each myFolder In myFolders
Debug.Print myFolder.Parent, myFolder.Name, _
myFolder.Items.Count
If myFolder.Name = "Master Contacts" Then
'I was looking to enumerate items in the Master Contacts Folder
'That's what's happening here.
For Each myContact In myFolder.Items
'Routine throws a type mismatch on the 69th iteration of this loop.
Debug.Print i & "--> " & myContact.FileAs
i = i + 1
Next
End If
Next
Set myOlApp = Nothing
End Sub