|
-
Nov 6th, 2002, 10:44 PM
#1
(Resolved) Search through Contacts gets error after 75 records (all the time)
I am searching through an Outlook Contacts folder and it gets a type mismatch after 75 record out of 110. I can not tell which record it is on for the search does not seem to be in any order that i know of but it is the same each time I run it. The code is correct so how can you get a type mismatch after reading 75 records???? The code is as follows: What can be the problem
The error is generated on the following line:
If olContact.Categories <> "" Then
at this point olContacts turns to equal Nothing
What happened???????
How do I correct it?
Dim i As Long
Dim j As Long
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olFolder As MAPIFolder
Dim olContact As ContactItem
Dim Cat() As String
Dim Addit As Boolean
Dim Name As String
Combo2.Clear
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderContacts) 'The Contacts Folder
For Each olContact In olFolder.Items
If olContact.Categories <> "" Then
Addit = True
Cat = Split(olContact.Categories, ",")
For i = 0 To UBound(Cat)
For j = 0 To Combo2.ListCount - 1
If Cat(i) = Combo2.List(j) Then
Addit = False
Exit For
End If
Next j
If Addit Then Combo2.AddItem Cat(i)
Addit = True
Next i
End If
Next
Last edited by randem; Nov 7th, 2002 at 08:17 AM.
-
Nov 7th, 2002, 04:24 AM
#2
Frenzied Member
Code looks good, so we are into guessing games....
Assume you have a bad item or a non-Contacts item in your contacts folder. If this is so, before checking to see if .Categories <> "", check to make sure it is really a Contacts item that is there. Check the type to see if it is olContactItem = 2.
-
Nov 7th, 2002, 06:10 AM
#3
PowerPoster
I can not tell which record it is on for the search does not seem to be in any order that i know of
my guess would be that since you can ask for a display of them ordered in several different ways there isn't any point in the app maintaining an ordered list and they are simply maintained internally in the order in which they were inserted, so it probably isn't much help but very likely the bad record is the 75th one to have been put into the data set.
-
Nov 7th, 2002, 07:44 AM
#4
JordanChris
I have tried various thing, I have just looped through to just printing the names to see what record this would be and the same thing happens. In Outlook it seems everything displays I have 110 items in the "Contacts" folder. What would make olContacts = Nothing in the middle of the loop???
This one's got me!!!. Just by accessing the record (what ever it is), but Outlook doesnt seem to have this problem.
ANY SUGGESTION OUT THERE!!!!?????!!!!
-
Nov 7th, 2002, 07:48 AM
#5
phinds,
How then can I ask for these record in a different fashion to find out which record is bad and which one it is? Unless this would happen in each different way I would access the records and each time the records came back in the same order as the contacts, how would I find this bugger!!!
Any Ideas, besides RAID!!!!
-
Nov 7th, 2002, 07:58 AM
#6
PowerPoster
Try dimming olContact as object
-
Nov 7th, 2002, 08:00 AM
#7
Thanks Everyone,
I found the problem, I had two distribution list in the contacts folder. The way I found this info out is I just deleted the non contact Items from the Contacts folder and Wa-La it works.
Now my problems is... Why would my search not let me know that these were not actual contact items and just BOMB!!!!!. Is there any way to test for this condition prior to bombing? After it bombs there is no recovery. On Error statement is useless because olContacts = Nothing at that point.
-
Nov 7th, 2002, 08:03 AM
#8
PowerPoster
Originally posted by randem
Thanks Everyone,
I found the problem, I had two distribution list in the contacts folder. The way I found this info out is I just deleted the non contact Items from the Contacts folder and Wa-La it works.
Now my problems is... Why would my search not let me know that these were not actual contact items and just BOMB!!!!!. Is there any way to test for this condition prior to bombing? After it bombs there is no recovery. On Error statement is useless because olContacts = Nothing at that point.
I think dimming olContact as Object might solve the crash problem ...
-
Nov 7th, 2002, 08:07 AM
#9
Frenzied Member
Did you check JordanChris his option ??
Check the type to see if it is olContactItem = 2
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 7th, 2002, 08:17 AM
#10
Muddy,
Thanks, You are indeed correct!!! I changed the olContact reference to Object and all is fine. What is the difference in this (besides the obvious, it works!)?????
-
Nov 7th, 2002, 08:35 AM
#11
PowerPoster
Originally posted by randem
Muddy,
Thanks, You are indeed correct!!! I changed the olContact reference to Object and all is fine. What is the difference in this (besides the obvious, it works!)?????
I'm not sure ... I ran into a similar problem and that was what "solved" it. I too dislike fixing something without understanding the underlying cause. Maybe someone else can explain why ...
-
Nov 7th, 2002, 09:27 AM
#12
Frenzied Member
If olContacts is DIMmed as an Object, then it can hold any Object - a ContactItem or a DistributionList item.
If olContacts is not DIMmed, then when it is first used it will be set up as an olContacts item. If you try to put a DistributionList item into this object it will say "No way".
-
Nov 7th, 2002, 09:43 AM
#13
PowerPoster
Originally posted by JordanChris
If olContacts is DIMmed as an Object, then it can hold any Object - a ContactItem or a DistributionList item.
If olContacts is not DIMmed, then when it is first used it will be set up as an olContacts item. If you try to put a DistributionList item into this object it will say "No way".
I would have thought, however, that if it were dimmed as a ContactItem that the "For Each" loop would only look at ContactItem objects and ignore other objects.
-
Nov 8th, 2002, 03:22 PM
#14
Just an update
If OlObjectClass.olContact <> olContact.Class Then ' Skip if not a contact Item
GoTo NextItem
End If
You don't have to define olObjectClass it is already defined by VB 6.0
This code should be used to determine if an object is a contactitem (or any other outlook object). Any type of outlook object can be in any folder!!!
Thanks All!!!
Last edited by randem; Nov 8th, 2002 at 03:42 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|