PDA

View Full Version : Runtime Error...Outlook 2007 bulk-convert Email1Address, VERY strange



alarian
09-11-2012, 04:04 AM
I want to change the e-mail address of all contacts in Outlook to lowercase and remove whitespaces.
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

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!

JP2112
09-14-2012, 12:29 PM
I want to change the e-mail address of all contacts in Outlook to lowercase and remove whitespaces.

May I ask why?

alarian
09-15-2012, 12:48 AM
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...
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

JP2112
09-17-2012, 09:35 AM
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.