Results 1 to 14 of 14

Thread: (Resolved) Search through Contacts gets error after 75 records (all the time)

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    (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.

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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.

  3. #3
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    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.

  4. #4

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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!!!!?????!!!!

  5. #5

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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!!!!

  6. #6
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Try dimming olContact as object

  7. #7

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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.

  8. #8
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    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 ...

  9. #9
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    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

  10. #10

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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!)?????

  11. #11
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    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 ...

  12. #12
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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".

  13. #13
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    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.


  14. #14

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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
  •  



Click Here to Expand Forum to Full Width