none
VBA code is unintentionally switching between custom form and default form RRS feed

  • Question

  • Hi

    The code which gives me problem now was working perfectly with Outlook 2003 and Small Business Server 2003 but we have now upgraded to Outlook 2010 and Exchange server 2010

    In a public folder I have published my cutsom designed form with a lot of user defined fields. The VBA code is accessing the contact items in that public folder and is manipulation the user defined fields. From time to time (mostly when the code is supposed to access quite a lot of contacts) the code stops and in the debugging I realise that for that particullar item the user defined fileds not are available. If I open the contact form I get the default form which explains why the code is stopping. When I restart the code will stop at another contact item and the error will be the same.The error seems to be inconsistant and i really don't know where to look for an error - espacially because i know the code has benne working before in another environment.

    Please give me advise on where to look for errors.

    - Allan

    Thursday, December 13, 2012 12:34 PM

Answers

  • You need to check the MessageClass of the items to see if it's your custom form's MessageClass or the standard MessageClass ("IPM.Contact"). If it's the standard MessageClass you should not expect to see your custom fields.
     
    You can convert all items in the folder to use your MessageClass, and set default values for items without the custom fields. You can also filter the folder's Items collection to only return items with your custom MessageClass.
     
    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:314dbd79-3165-4ec b-9b47-23a3376696a1...

    Hi

    The code which gives me problem now was working perfectly with Outlook 2003 and Small Business Server 2003 but we have now upgraded to Outlook 2010 and Exchange server 2010

    In a public folder I have published my cutsom designed form with a lot of user defined fields. The VBA code is accessing the contact items in that public folder and is manipulation the user defined fields. From time to time (mostly when the code is supposed to access quite a lot of contacts) the code stops and in the debugging I realise that for that particullar item the user defined fileds not are available. If I open the contact form I get the default form which explains why the code is stopping. When I restart the code will stop at another contact item and the error will be the same.The error seems to be inconsistant and i really don't know where to look for an error - espacially because i know the code has benne working before in another environment.

    Please give me advise on where to look for errors.

    - Allan


    Ken Slovak MVP - Outlook
    Thursday, December 13, 2012 2:29 PM
    Moderator
  • It definitely sounds like a memory issue, most likely an RPC channel issue in my opinion. That's unusual in VBA code, but let's see if we can work around that.
     
    I would add code to set oProp and oProps to Nothing in each loop pass. At least for testing, I'd also comment out the use of With and use the fully qualified form, i.e. Set oProps = objContact.UserProperties and so on. Just as a belt and suspenders type thing I'd also add code to test for oProp being instantiated each time before it's used:
     
    Set oProp = oProps.Find("X-Kategori")
    If (oProp Is Nothing) Then
       ' add the property
    Else
        ' get/set the property value


    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:1ead0b42-d34a-46dc-b422-44c86b45fd02...
    I tried to add the error handling you suggested. I never end up in not having a contact folder or a contact object to handle.
    I also rewrote the code regarding the user defined properties. Somehow it made a change. When i strip all my code so that i not will have to give an user defined property a new value I am able to to throuh all my items but if i want to set values I _sometimes_ run into problems. If I go through less than 400 items I will be able to run the code but if i exceed this "invisable" limit to say 1000 items i end up with the same error. Doesn't that implicate some kind of memory or garbage collection proplem?

    Below you can see the code. If I remove the line with the "value set problem" comment I can go all the way. If I add the line I can go through the items but only if not exceeding some number of around 400-500 items in the collection.

    It makes no difference if I use
       .UserProperties("X-Kategori") = "2,3"
    instead.

    So I am still pretty much stuck......



    Sub Update_Xnet_categories()
        
        Dim last_X_net As String
        Dim oProps As Outlook.UserProperties
        Dim oProp As Outlook.UserProperty
        
        Set objNameSpace = Application.GetNamespace("MAPI")
        Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
        
        If Not (objContactFolder Is Nothing) Then
            Set objContacts = objContactFolder.Items
            If Not (objContacts Is Nothing) Then
                timestart = Now()
                counter = 0
                For intcounter = 1 To 1000 'objContacts.Count
                    Set objContact = objContacts.Item(intcounter)
                    If Not (objContact Is Nothing) Then
                        With objContact
                            Set oProps = ..UserProperties
                            Set oProp = oProps.Find("X-Kategori")
                            last_X_net = oProp.Value               ' ERROR LINE
                            'last_X_net = ..UserProperties("X-Kategori")
                            
                            oProp.Value = "2,3"                    ' value set problem
                            
                            If last_X_net <> oProp.Value Then
                                '.Save
                                counter = counter + 1
                            End If
                            last_X_net = ""
                        End With
                    Else
                        objerr = 3
                        GoTo OE
                    End If
                    Set objContact = Nothing
                Next
                timeend = Now()
                TimeDiff = timeend - timestart
            Else
                objerr = 2
                GoTo OE
            End If
        Else
            objerr = 1
    OE:     MsgBox "Object error: " & objerr
        End If

        Set objNameSpace = Nothing
        Set objContactFolder = Nothing
        Set objContacts = Nothing

        MsgBox counter & " updates done in " & DateDiff("s", timestart, timeend) & " seconds!"

    End Sub

    Ken Slovak MVP - Outlook
    Tuesday, December 18, 2012 7:14 PM
    Moderator

All replies

  • You need to check the MessageClass of the items to see if it's your custom form's MessageClass or the standard MessageClass ("IPM.Contact"). If it's the standard MessageClass you should not expect to see your custom fields.
     
    You can convert all items in the folder to use your MessageClass, and set default values for items without the custom fields. You can also filter the folder's Items collection to only return items with your custom MessageClass.
     
    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:314dbd79-3165-4ec b-9b47-23a3376696a1...

    Hi

    The code which gives me problem now was working perfectly with Outlook 2003 and Small Business Server 2003 but we have now upgraded to Outlook 2010 and Exchange server 2010

    In a public folder I have published my cutsom designed form with a lot of user defined fields. The VBA code is accessing the contact items in that public folder and is manipulation the user defined fields. From time to time (mostly when the code is supposed to access quite a lot of contacts) the code stops and in the debugging I realise that for that particullar item the user defined fileds not are available. If I open the contact form I get the default form which explains why the code is stopping. When I restart the code will stop at another contact item and the error will be the same.The error seems to be inconsistant and i really don't know where to look for an error - espacially because i know the code has benne working before in another environment.

    Please give me advise on where to look for errors.

    - Allan


    Ken Slovak MVP - Outlook
    Thursday, December 13, 2012 2:29 PM
    Moderator
  • You need to check the MessageClass of the items to see if it's your custom form's MessageClass or the standard MessageClass ("IPM.Contact"). If it's the standard MessageClass you should not expect to see your custom fields.
     
    You can convert all items in the folder to use your MessageClass, and set default values for items without the custom fields. You can also filter the folder's Items collection to only return items with your custom MessageClass.
     
    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:314dbd79-3165-4ec b-9b47-23a3376696a1...

    Hi

    The code which gives me problem now was working perfectly with Outlook 2003 and Small Business Server 2003 but we have now upgraded to Outlook 2010 and Exchange server 2010

    In a public folder I have published my cutsom designed form with a lot of user defined fields. The VBA code is accessing the contact items in that public folder and is manipulation the user defined fields. From time to time (mostly when the code is supposed to access quite a lot of contacts) the code stops and in the debugging I realise that for that particullar item the user defined fileds not are available. If I open the contact form I get the default form which explains why the code is stopping. When I restart the code will stop at another contact item and the error will be the same.The error seems to be inconsistant and i really don't know where to look for an error - espacially because i know the code has benne working before in another environment.

    Please give me advise on where to look for errors.

    - Allan


    Ken Slovak MVP - Outlook
    Thursday, December 13, 2012 2:30 PM
    Moderator
  • I have done that and every single item named with my custom MessageClass.

    The strange thing is that when running the code the messageClass is obiously changeing on-the-fly for some items.

    I don't know if it could mean any difference but I am running the code in a public folder in a subfolder of Favorites?

    In my other environment with Outlook 2003 and SBS 2003 it didn't mean any difference - it just worked.

    - Allan

    Thursday, December 13, 2012 4:12 PM
  • I've never heard of a MessageClass changing on the fly unless some code changes it. Is any other code running?
     
    I'd recommend using a MAPI viewer, such as OutlookSpy or MFCMAPI and looking at the items which you have problems with. See what the MessageClass shows, as well as any user properties or MAPI named properties.
     
    Obviously the folder is set up OK, as most of the items are correct.
     
    I'd also check to see if any of the items that cause problems are one-offed. MailItem.FormDescription.OneOff will tell you that. You can get the MailItem reference from Application.ActiveExplorer.Selection.Item(1) if you select the item in the folder view and check in VBA code.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:45c74663-3659-4d6c-a50d-81215aec64de...

    I have done that and every single item named with my custom MessageClass.

    The strange thing is that when running the code the messageClass is obiously changeing on-the-fly for some items.

    I don't know if it could mean any difference but I am running the code in a public folder in a subfolder of Favorites?

    In my other environment with Outlook 2003 and SBS 2003 it didn't mean any difference - it just worked.

    - Allan


    Ken Slovak MVP - Outlook
    Thursday, December 13, 2012 6:07 PM
    Moderator
  • I find it strange too....

    Here is how I have been debugging until now:

    1) running the VBA-code

    2) error '91' rises

    3) in debugging mode I do a mouse-over on the objItem to identify the item which is causing the error

    4) stopping the code from running

    5) locating the objitem whcih caused the error in the public folder

    6) opening the contactitem will show the item with a default form

    7) closing outlook

    8) opening outlook

    9) finding and opening the above mentioned ObjItem shows now with my Custom Form.....again.

    Watching the default form made me think the MessageClass changed on the fly. Your debugging advise turned me to another step in debugging. I added a watch on objItem and investigating that obj as step 3.a). it turns out that the messageClass is my Custom Form but nevertheless the code stops. After reopening outlook the code will proceed to another item which will fail but the initial one which caused the first error will have disappered.

    Sometimes outlook is showing me an error, something like this: "...it has encountered a problem and that outlook will have to restart - send report?"

    Thursday, December 13, 2012 8:07 PM
  • It sounds like something is getting corrupted if you need to close and reopen Outlook for the correct MessageClass to be used. I would use a MAPI viewer, as I had said, and examine the problem items both before and after the code runs.
     
    You also should post the code you're using, if it's not too long, so people can look at it. If that's the only code that's running in Outlook it's doing something wrong. If other code is running in Outlook disable it for the moment.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:866a4abd-67ab-4ec8-97e4-d8a72153f050...

    I find it strange too....

    Here is how I have been debugging until now:

    1) running the VBA-code

    2) error '91' rises

    3) in debugging mode I do a mouse-over on the objItem to identify the item which is causing the error

    4) stopping the code from running

    5) locating the objitem whcih caused the error in the public folder

    6) opening the contactitem will show the item with a default form

    7) closing outlook

    8) opening outlook

    9) finding and opening the above mentioned ObjItem shows now with my Custom Form.....again.

    Watching the default form made me think the MessageClass changed on the fly. Your debugging advise turned me to another step in debugging. I added a watch on objItem and investigating that obj as step 3.a). it turns out that the messageClass is my Custom Form but nevertheless the code stops. After reopening outlook the code will proceed to another item which will fail but the initial one which caused the first error will have disappered.

    Sometimes outlook is showing me an error, something like this: "...it has encountered a problem and that outlook will have to restart - send report?"


    Ken Slovak MVP - Outlook
    Thursday, December 13, 2012 10:23 PM
    Moderator
  • OK Ken, thank you.

    I have downloaded MFCMAPI viewer.

    I run the application/viewer on my client where the VBA code is supposed to run. After running the VBA code to the point of error I go to MDB->Public Folder->Open Public Folder Store...

    Then I look for the item which causes the error in the VBA code (identified by a mouse-over). Investigating the data of this special item I conclude that the MessageClass is my custom From and i can find the userdefined prop which obviously is empty when I run the code but has a valid value when I look at the item with the viewer. I found what i expected to find but I still can't figure out why the code stops:-(

    I have pasted the code to this post and with "ERROR:" pointed out the line where the debugger is stopping. "Spellfavorites" is just returning the string identifying the favorites folder (We have both English and Danish versions of Outlook running on different clients)

    The code is not only stopping on my client but on every client tested yet.

    Initially my code would save data but if I omit that the code still stops and what is most weird is that it stops at another item next time i run the code.

       Set objNameSpace = Application.GetNamespace("MAPI")
       Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
       Set objContacts = objContactFolder.Items
        
        timestart = Now()
        counter = 0
        
        For intcounter = 1 To 3600 'objContacts.Count
            Set objContact = objContacts.Item(intcounter)
            With objContact
    ERROR:            last_X_net = .UserProperties("X-Kategori")

    Friday, December 14, 2012 9:53 AM
  • OK, error 91 is Object variable or With block variable not set. So the object you're referencing isn't set.
     
    Your code doesn't make a lot of sense to me, especially the loop part. What exactly is last_X_net ?
     
    I would write the code with some error handling and change the looping completely:
     
        Dim oProps As Outlook.UserProperties
        Dim oProp As Outlook.UserProperty

       Set objNameSpace = Application.GetNamespace("MAPI")
       Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
       If Not (objContactFolder Is Nothing) Then

            Set objContacts = objContactFolder.Items
            If Not (objContacts Is Nothing) Then
                timestart = Now()
                counter = 0
        
                For intcounter = 1 To objContacts.Count
                    Set objContact = objContacts.Item(intcounter)

                    If Not (objContact Is Nothing) Then
                        With objContact

                        Set oProps = ..UserProperties

                        Set oProp = oProps.Find("X-Kategori")

                        If Not (oProp Is Nothing) Then

                            last_X_net = oProp.Value

                            ' etc.

    And set all the objects to Nothing after using them in each loop pass.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:cba8dca7-6188-4df8-a662-9ec616797552...

    OK Ken, thank you.

    I have downloaded MFCMAPI viewer.

    I run the application/viewer on my client where the VBA code is supposed to run. After running the VBA code to the point of error I go to MDB->Public Folder->Open Public Folder Store...

    Then I look for the item which causes the error in the VBA code (identified by a mouse-over). Investigating the data of this special item I conclude that the MessageClass is my custom From and i can find the userdefined prop which obviously is empty when I run the code but has a valid value when I look at the item with the viewer. I found what i expected to find but I still can't figure out why the code stops:-(

    I have pasted the code to this post and with "ERROR:" pointed out the line where the debugger is stopping. "Spellfavorites" is just returning the string identifying the favorites folder (We have both English and Danish versions of Outlook running on different clients)

    The code is not only stopping on my client but on every client tested yet.

    Initially my code would save data but if I omit that the code still stops and what is most weird is that it stops at another item next time i run the code.

       Set objNameSpace = Application.GetNamespace("MAPI")
       Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
       Set objContacts = objContactFolder.Items
        
        timestart = Now()
        counter = 0
        
        For intcounter = 1 To 3600 'objContacts.Count
            Set objContact = objContacts.Item(intcounter)
            With objContact
    ERROR:            last_X_net = .UserProperties("X-Kategori")


    Ken Slovak MVP - Outlook
    Friday, December 14, 2012 6:34 PM
    Moderator
  • I tried to add the error handling you suggested. I never end up in not having a contact folder or a contact object to handle.
    I also rewrote the code regarding the user defined properties. Somehow it made a change. When i strip all my code so that i not will have to give an user defined property a new value I am able to to throuh all my items but if i want to set values I _sometimes_ run into problems. If I go through less than 400 items I will be able to run the code but if i exceed this "invisable" limit to say 1000 items i end up with the same error. Doesn't that implicate some kind of memory or garbage collection proplem?

    Below you can see the code. If I remove the line with the "value set problem" comment I can go all the way. If I add the line I can go through the items but only if not exceeding some number of around 400-500 items in the collection.

    It makes no difference if I use
       .UserProperties("X-Kategori") = "2,3"
    instead.

    So I am still pretty much stuck......



    Sub Update_Xnet_categories()
        
        Dim last_X_net As String
        Dim oProps As Outlook.UserProperties
        Dim oProp As Outlook.UserProperty
        
        Set objNameSpace = Application.GetNamespace("MAPI")
        Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
        
        If Not (objContactFolder Is Nothing) Then
            Set objContacts = objContactFolder.Items
            If Not (objContacts Is Nothing) Then
                timestart = Now()
                counter = 0
                For intcounter = 1 To 1000 'objContacts.Count
                    Set objContact = objContacts.Item(intcounter)
                    If Not (objContact Is Nothing) Then
                        With objContact
                            Set oProps = .UserProperties
                            Set oProp = oProps.Find("X-Kategori")
                            last_X_net = oProp.Value               ' ERROR LINE
                            'last_X_net = .UserProperties("X-Kategori")
                            
                            oProp.Value = "2,3"                    ' value set problem
                            
                            If last_X_net <> oProp.Value Then
                                '.Save
                                counter = counter + 1
                            End If
                            last_X_net = ""
                        End With
                    Else
                        objerr = 3
                        GoTo OE
                    End If
                    Set objContact = Nothing
                Next
                timeend = Now()
                TimeDiff = timeend - timestart
            Else
                objerr = 2
                GoTo OE
            End If
        Else
            objerr = 1
    OE:     MsgBox "Object error: " & objerr
        End If

        Set objNameSpace = Nothing
        Set objContactFolder = Nothing
        Set objContacts = Nothing

        MsgBox counter & " updates done in " & DateDiff("s", timestart, timeend) & " seconds!"

    End Sub
    Sunday, December 16, 2012 12:12 PM
  • I tried to add the error handling you suggested. I never end up in not having a contact folder or a contact object to handle.
    I also rewrote the code regarding the user defined properties. Somehow it made a change. When i strip all my code so that i not will have to give an user defined property a new value I am able to to throuh all my items but if i want to set values I _sometimes_ run into problems. If I go through less than 400 items I will be able to run the code but if i exceed this "invisable" limit to say 1000 items i end up with the same error. Doesn't that implicate some kind of memory or garbage collection proplem?

    Below you can see the code. If I remove the line with the "value set problem" comment I can go all the way. If I add the line I can go through the items but only if not exceeding some number of around 400-500 items in the collection.

    It makes no difference if I use
       .UserProperties("X-Kategori") = "2,3"
    instead.

    So I am still pretty much stuck......



    Sub Update_Xnet_categories()
        
        Dim last_X_net As String
        Dim oProps As Outlook.UserProperties
        Dim oProp As Outlook.UserProperty
        
        Set objNameSpace = Application.GetNamespace("MAPI")
        Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
        
        If Not (objContactFolder Is Nothing) Then
            Set objContacts = objContactFolder.Items
            If Not (objContacts Is Nothing) Then
                timestart = Now()
                counter = 0
                For intcounter = 1 To 1000 'objContacts.Count
                    Set objContact = objContacts.Item(intcounter)
                    If Not (objContact Is Nothing) Then
                        With objContact
                            Set oProps = .UserProperties
                            Set oProp = oProps.Find("X-Kategori")
                            last_X_net = oProp.Value               ' ERROR LINE
                            'last_X_net = .UserProperties("X-Kategori")
                            
                            oProp.Value = "2,3"                    ' value set problem
                            
                            If last_X_net <> oProp.Value Then
                                '.Save
                                counter = counter + 1
                            End If
                            last_X_net = ""
                        End With
                    Else
                        objerr = 3
                        GoTo OE
                    End If
                    Set objContact = Nothing
                Next
                timeend = Now()
                TimeDiff = timeend - timestart
            Else
                objerr = 2
                GoTo OE
            End If
        Else
            objerr = 1
    OE:     MsgBox "Object error: " & objerr
        End If

        Set objNameSpace = Nothing
        Set objContactFolder = Nothing
        Set objContacts = Nothing

        MsgBox counter & " updates done in " & DateDiff("s", timestart, timeend) & " seconds!"

    End Sub
    Sunday, December 16, 2012 12:12 PM
  • It definitely sounds like a memory issue, most likely an RPC channel issue in my opinion. That's unusual in VBA code, but let's see if we can work around that.
     
    I would add code to set oProp and oProps to Nothing in each loop pass. At least for testing, I'd also comment out the use of With and use the fully qualified form, i.e. Set oProps = objContact.UserProperties and so on. Just as a belt and suspenders type thing I'd also add code to test for oProp being instantiated each time before it's used:
     
    Set oProp = oProps.Find("X-Kategori")
    If (oProp Is Nothing) Then
       ' add the property
    Else
        ' get/set the property value


    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "AllanReese" <=?utf-8?B?QWxsYW5SZWVzZQ==?=> wrote in message news:1ead0b42-d34a-46dc-b422-44c86b45fd02...
    I tried to add the error handling you suggested. I never end up in not having a contact folder or a contact object to handle.
    I also rewrote the code regarding the user defined properties. Somehow it made a change. When i strip all my code so that i not will have to give an user defined property a new value I am able to to throuh all my items but if i want to set values I _sometimes_ run into problems. If I go through less than 400 items I will be able to run the code but if i exceed this "invisable" limit to say 1000 items i end up with the same error. Doesn't that implicate some kind of memory or garbage collection proplem?

    Below you can see the code. If I remove the line with the "value set problem" comment I can go all the way. If I add the line I can go through the items but only if not exceeding some number of around 400-500 items in the collection.

    It makes no difference if I use
       .UserProperties("X-Kategori") = "2,3"
    instead.

    So I am still pretty much stuck......



    Sub Update_Xnet_categories()
        
        Dim last_X_net As String
        Dim oProps As Outlook.UserProperties
        Dim oProp As Outlook.UserProperty
        
        Set objNameSpace = Application.GetNamespace("MAPI")
        Set objContactFolder = GetPublicFolder(SpellFavorites & "\SPF\Spillere")
        
        If Not (objContactFolder Is Nothing) Then
            Set objContacts = objContactFolder.Items
            If Not (objContacts Is Nothing) Then
                timestart = Now()
                counter = 0
                For intcounter = 1 To 1000 'objContacts.Count
                    Set objContact = objContacts.Item(intcounter)
                    If Not (objContact Is Nothing) Then
                        With objContact
                            Set oProps = ..UserProperties
                            Set oProp = oProps.Find("X-Kategori")
                            last_X_net = oProp.Value               ' ERROR LINE
                            'last_X_net = ..UserProperties("X-Kategori")
                            
                            oProp.Value = "2,3"                    ' value set problem
                            
                            If last_X_net <> oProp.Value Then
                                '.Save
                                counter = counter + 1
                            End If
                            last_X_net = ""
                        End With
                    Else
                        objerr = 3
                        GoTo OE
                    End If
                    Set objContact = Nothing
                Next
                timeend = Now()
                TimeDiff = timeend - timestart
            Else
                objerr = 2
                GoTo OE
            End If
        Else
            objerr = 1
    OE:     MsgBox "Object error: " & objerr
        End If

        Set objNameSpace = Nothing
        Set objContactFolder = Nothing
        Set objContacts = Nothing

        MsgBox counter & " updates done in " & DateDiff("s", timestart, timeend) & " seconds!"

    End Sub

    Ken Slovak MVP - Outlook
    Tuesday, December 18, 2012 7:14 PM
    Moderator
  • Thank you very much for advising me. I will try to follow the suggested steps

    - Allan

    Tuesday, December 18, 2012 8:03 PM
  • After a couple of days os I am back again. unfortunately i still have the same problem as the reducing of coed as you mentioned not helped me out.

    Will I be able to force Outlook to allocate more memory or can I force a better garbage colloction. Right now I am only reducing memory usage by setting a couple of objects to Nothing in each loop, like:

                            Set oProps = Nothing
                            Set oProp = Nothing

                            Set objContact = Nothing

    I don't wee what else I can do to reduce memory usage.

    Another thing I tried was to disconnect to the exchange server and try to run the code in offline mode. Didn't help either BUT I had to modify the code in order of get hold of the right folder.

    I use a common known code called GetDefaultFolder where I traverse the folder tree by locating the top level with

            Set objFolder = objNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders).Parent

    Its working in online mode but in offline mode objFolder ends up with Nothing and instaead I have to use

            usermail = Application.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
            Set objFolder = objNameSpace.Folders("Offentlige mapper - " & usermail)

    Maybe this also is caused by the RPC channel issue you were talking about?

    Investigating connection state of Outlook I can see 4 asyncronious RPC connections. I don't know if that is reasonable but that is how it is.....

    Friday, January 4, 2013 12:42 PM