Consulting

Results 1 to 4 of 4

Thread: Runtime Error...Outlook 2007 bulk-convert Email1Address, VERY strange

  1. #1
    VBAX Newbie
    Joined
    Sep 2012
    Posts
    3
    Location

    Angry Runtime Error...Outlook 2007 bulk-convert Email1Address, VERY strange

    I want to change the e-mail address of all contacts in Outlook to lowercase and remove whitespaces.
    [VBA]Sub ReFileContacts()
    Dim items As items, item As ContactItem, folder As folder
    Dim contactItems As Outlook.items
    Dim itemContact As Outlook.ContactItem

    Set folder = Session.GetDefaultFolder(olFolderContacts)
    Set items = folder.items
    Count = items.Count
    If Count = 0 Then
    MsgBox "Nothing to do!"
    Exit Sub
    End If

    'Filter on the message class to obtain only contact items in the folder
    Set contactItems = items.Restrict("[MessageClass]='IPM.Contact.112607'")

    For Each itemContact In contactItems 'Loop through all contacts
    itemContact.Email1Address = LCase(Trim(Replace(itemContact.Email1Address)))
    itemContact.Save 'Save the contact
    Next

    MsgBox "Your contacts have been converted to lowercase without whitespaces."
    End Sub[/VBA]

    These contacts use a custom form hence the IPM.Contact.112607

    When I run this (Contact folder has 20.000 contacts) I get the following error:

    runtime error -1836974071 (92820009)
    one or more items in the folder you synchronized do not match.
    to resolve the conflicts, open the items and try the operation again

    I really have no idea where to go from here...
    I did NOT expect this kind of error.
    If you run this script in your Outlook, you will definitely not get this error.
    If you do, make sure you change
    Set contactItems = items.Restrict("[MessageClass]='IPM.Contact.112607'")
    to your corresponding form.
    Please note:
    I know that the field is called Email1Address because msgbox(itemContact.Email1Address) returns the E-mail address value.

    Thank you!

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    I want to change the e-mail address of all contacts in Outlook to lowercase and remove whitespaces.
    May I ask why?
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    VBAX Newbie
    Joined
    Sep 2012
    Posts
    3
    Location

    Thumbs down

    Quote Originally Posted by JP2112
    May I ask why?
    I'm doing this for a client.
    It's a bit frustrating because the client doesn't understand that the error is unrelated to the code and is not solved by changing the code but by troubleshooting the issue.
    Either way, I'm sending this project to arbitration now because noone seems to know what causes this issue, including microsoft. But everyone can conclude that besides checking if the e-mail needs to be changed, the code is next to best practice...
    [VBA]For Each itemContact In contactItems 'Loop through all contacts
    strOldAddress = itemContact.Email1Address
    strNewAddress = LCase(Trim(Replace(strOldAddress , " ", "")))
    if StrComp(strOldAddress, strNewAddress, 0) <> 0 Then
    itemContact.Email1Address =
    itemContact.Save 'Save the contact
    End If
    Next [/VBA]

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Why are you so sure that anyone reading this and pasting the code into their Outlook won't get the same error?

    Based on what I found after a search, it looks like the contacts need to be synchronized.

    I pasted your code into Outlook and found a few other issues:

    1) The variable "count" is not declared.
    2) The Replace Function needs something to replace.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •