Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / May 2004

Tip: Looking for answers? Try searching our database.

Changing Contact Phone Number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guy - 28 May 2004 11:13 GMT
I am using the following code:
Sub ChangeNumber()
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = _
   myNameSpace.GetDefaultFolder(olFolderContacts)
Set itmContact = myFolder.Items
Dim I As Integer

For I = 1 To itmContact.Count
   If Left(itmContact(I).BusinessTelephoneNumber, 4)
= "+972" Then
       bphone = itmContact(I).BusinessTelephoneNumber
       itmContact(I).BusinessTelephoneNumber.erase
       itmContact(I).BusinessTelephoneNumber = "0" + Mid
(bphone, 7, 1) + "-" + Mid(bphone, 10, 10)
       itmContact(I).Save
   End If
Next
End Sub

It is not changing the telephone number. At some point
when i was stepping through the code, it worked, but when
i ran the macro it did not work. I do not know what i did
to make it work.
Andrew Cushen - 28 May 2004 16:08 GMT
Did you read my answer to your earlier post? I don't see
where you're checking if itmContact(I) is actually a
COntact item. Remember, you can have different types of
items in your COntacts folder, like Distribution Lists.
Just because an item is in your Contacts folder, doesn't
make it a Contact item.
Try this If Test before you test for the 972 area code:

>-----Original Message-----
>I am using the following code:
[quoted text clipped - 23 lines]
>to make it work.
>.
Guy Perry - 28 May 2004 16:37 GMT
Yes, i read it, thank you. I added the Save as you recommended but it
did not help.
I now also added the line you suggested, and it is a Contact item, but
still it did not work.
When i am debugging the code it seems all to work fine. It meets the IF
criteria and the variable gets the correct value. The problem occurs
when it tries to assign the value to the
itmContact(I).BusinessTelephoneNumber = NewNumber. It simply does not
change the value.
Any other suggestions?
Andrew Cushen - 28 May 2004 16:13 GMT
Sorry, accidentally posted my last before I finished.

Try this:

If itmContact(I).Class = olContact Then
  'Pick up your code:
   If Left(itmContact(I).BusinessTelephoneNumber, 4) _
   "+972" Then
   'etc.

Not sure if that will fix your problem, but it needs to be
done either way. You'll either get an error, or your code
just won't work, if you try to process an item that isn't
a Contact Item.

HTH,

-Andrew
=====================================

>-----Original Message-----
>I am using the following code:
[quoted text clipped - 23 lines]
>to make it work.
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.