Searching through folder w/ Custom Forms

  • Thread starter Thread starter Koops
  • Start date Start date
K

Koops

Using the following code I get an error once I get to the
half way point of the search. There is a custom form
used for these items. Every item uses the custom form.
The error I get is:
Method 'CompanyName' of object 'ContactItem' failed. But
it's not because it's a different object type.

For Each oContact In oFolder.Items
cName = c.CompanyName
Next

Thanks
 
Use the Class property to check whether you have an actual ContactItem. My
guess is that you struck a distribution list, which of course has no
CompanyName property.
 
Thanks for the suggestions but that's not the issue.
The weird thing is that it comes up with the error, and
if I use F8 to step through the code it has no problem
with that field. If I break it just before the half way
point and step through a couple items then hit F5, it
runs fine.
I don't get it...
 
You might want to show a larger code snippet, and tell us your Outlook
version and whether you're running this code against an Exchagne folder or a
..pst folder.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I'm running it against an Exchange Public Folder. My
version is Outlook 2003, although it didn't work on XP
either.
Here is the entire code bit of code:

Dim oContact As Object

Set oNameSpace = Application.GetNamespace("MAPI")
Set oFolder = oNameSpace.PickFolder

For Each oContact In oFolder.Items
If oContact.Class = olContact Then
cName = oContact.CompanyName
End If
Next
 
Back
Top