CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2001
    Location
    USA
    Posts
    75

    how to detect value not valid

    Hi.
    I am looping through the properties of an object (Outlook COntactObject) and I get an error -
    "Cant complete operation. One of the object parameters is not valid"

    this object parameter is here :

    myContact.ItemProperties.Item(ContactPropCounter).Value

    for some properties there are no .Value.


    Question:
    is there a way to detect in
    myContact.ItemProperties.Item(ContactPropCounter).Value is valid so that I can skip it and continue looping through other properties?

    Thanks.
    This forum is the best.

    -_-_-_-_-_-_
    AM

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    did you try...

    on error resume next
    ....
    myContact.ItemProperties.Item(ContactPropCounter).Value
    .....
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Sep 2001
    Location
    USA
    Posts
    75
    Yes. Somehow when I try to store everything
    when using

    On error resume next

    the string where I store all the stuff breaks on the first achieved error.
    If using msgBox to display - it displays everything needed though.

    Somehow if I was to use this "On error resume next" I need to store a piece of text then pass it to the string so it will save before the error occurs and after as well (there are more then one error)

    If u understand what I mean. Hm. I am confused myself a little.

  4. #4
    Join Date
    Jun 2002
    Location
    Lyman ME - USA | Oneonta NY - USA
    Posts
    399
    post your code so we can look at it all...see what could be going wrong...because i don't understand waht you are talking about with a string being displayed but broken and then the msgbox showing everything etc...

    thanks

    - nc
    "In a world without walls and barriers, what need is there for windows and gates!" - a mac ad
    "What was the best thing before sliced bread and when did sliced bread go out of existence?" - me
    "Software is like sex, it's better when it's free." - Linus Torvalds <- gotten from Andreas Masur


    Live Penguine! - Tux the linux mascot
    Vivez le penguine!, ¡Viva en penguine!, Lang lebe der Pinguin!, Viva no penguine!, Viva sul penguine!

  5. #5
    Join Date
    Sep 2001
    Location
    USA
    Posts
    75

    Arrow

    Here's the code. ContactPropCounter is set to 0 before the loop
    myContact is a contact from Outlook.
    This look displays all the properties in the messageBox and stores in the string. SOmehow even when all the properties are displayed in the messageBox in the string they are stored only until the first error occurs.
    _______________-----------------------
    Code:
    Do While ContactPropCounter < myContact.ItemProperties.count
    On Error Resume Next
                
      If myContact.ItemProperties.Item(ContactPropCounter).Value <> "" Then
          MsgBox myContact.ItemProperties.Item ContactPropCounter).Name & ":::" & ContactPropCounter & "::" & myContact.ItemProperties.Item(ContactPropCounter).Type & ":" & myContact.ItemProperties.Item(ContactPropCounter).Value
         contactString = contactString & myContact.ItemProperties.Item(ContactPropCounter).Name & ":" & myContact.ItemProperties.Item(ContactPropCounter).Value & ";"
       End If
            
       ContactPropCounter = ContactPropCounter + 1
          
    Loop

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Question something strange....


    Msdn showed an example with mailitem.
    Trying to do the same wirh contactItems
    raised an error (object does not support property or method)
    That is referred to
    myContact.ItemProperties
    So:
    are you using it inisde Vb or outlook?
    And - more important - how you declared
    myContact
    ? It is not an Outlook.ContactItem, is it?
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Sep 2001
    Location
    USA
    Posts
    75
    Here's full code.
    myContact does have itemProperties.
    the error is here :
    myContact.ItemProperties.Item(ContactPropCounter).Value
    when there is no parameter (.value)

    Another thing :

    myContact.ItemProperties.Item(ContactPropCounter).Name
    always works fine becuase (.name) exists with all the itemproperties

    ---------------
    thanks for asking. Full code (all of it) :
    I USE OUTLOOK MACRO (VBA)

    Code:
    Dim strConact As String
    Dim MyOLApp As New Outlook.Application
    Dim myNameSpace As NameSpace
    Dim myContacts As Items
    Dim myContact As ContactItem
    
    Dim objItem As Variant
    Set myNameSpace = MyOLApp.GetNamespace("MAPI")
    
    For Each objItem In myNameSpace.GetDefaultFolder(olFolderContacts).Items
            
              
        If TypeOf objItem Is Outlook.ContactItem Then
        contactString = ""
        userIDString = ""
        
        
        Set myContact = objItem
        MsgBox myContact.EntryID
        Dim ContactPropCounter As Integer
        ContactPropCounter = 0
        userIDString = myContact.EntryID
        
        Do While ContactPropCounter < myContact.ItemProperties.count
        On Error Resume Next
               
                If  myContact.ItemProperties.Item(ContactPropCounter).Value <> "" Then
            MsgBox myContact.ItemProperties.Item(ContactPropCounter).Name & ":::" & ContactPropCounter & "::" & myContact.ItemProperties.Item(ContactPropCounter).Type & ":" & myContact.ItemProperties.Item(ContactPropCounter).Value
                contactString = contactString & myContact.ItemProperties.Item(ContactPropCounter).Name & ":" & myContact.ItemProperties.Item(ContactPropCounter).Value & ";"
                End If
            
            ContactPropCounter = ContactPropCounter + 1
                    
        Loop
          contactString = contactString & ";"
          
           End If
    Next
    
    
    
    'MyOLApp.Quit
    Set myContacts = Nothing
    Set myNameSpace = Nothing
    Set MyOLApp = Nothing

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Question mmmmm!!!

    First:
    This is not full code:
    contactString
    userIDString
    are not declared (or you do not have the option explicit clause)
    Second: tried your code in Vba (outlook 2000). Still not found the
    myContact.ItemProperties
    So, I guess you're using Xp.
    In any case, a solution may be: if you find out some few
    property itmes do not have the "value" property,
    you can check for their names and skip them in the
    looping cycle.
    Hope this may help you
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  9. #9
    Join Date
    Sep 2001
    Location
    USA
    Posts
    75
    Yes I am using XP.
    This is strage because I would want my macros to be WIn XX compatible (not only XP).

    I have also found that there is a type for each itemProperty
    for most of the ones without the .value, .type=0. Meaning that i can avoid most of the errors by comaring w/ .type<>0.

    Thanks for the help CImperiali.

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

Featured