A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Find a contact by telephone number



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 4th 06, 03:29 PM posted to microsoft.public.outlook.program_vba
Angus Comber
external usenet poster
 
Posts: 2
Default Find a contact by telephone number

Hello

In Outlook I can use the Find Items feature to find a contact.

Eg I can look for 01222 & 456789

How can I do the same using VB?

Angus


Ads
  #2  
Old April 4th 06, 09:52 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Find a contact by telephone number

You can use the Restrict method. Here's an example built from the one in
the Help file:

Public Sub ContactPhoneNumber()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Ite ms
Set myItems = myContacts.Restrict("[BusinessTelephoneNumber] = '+1 (555)
555-1234'")
For Each myItem In myItems
If (myItem.Class = olContact) Then
Debug.Print myItem.FullName
End If
Next
End Sub

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Angus Comber" wrote:

Hello

In Outlook I can use the Find Items feature to find a contact.

Eg I can look for 01222 & 456789

How can I do the same using VB?

Angus



  #3  
Old April 7th 06, 01:57 PM posted to microsoft.public.outlook.program_vba
Angus Comber
external usenet poster
 
Posts: 2
Default Find a contact by telephone number

Thanks that's really helpful. However, the problem is most people enter a
telephone number with spaces. In UK a London telephone number might be 020
8888 9999

I get from a phone system 022088889999

Any ideas on how I can do a generic search which eg ignores spaces. Or
ideally where I can ignore spaces, brackets, hyphens?

Angus

"Eric Legault [MVP - Outlook]" wrote in
message ...
You can use the Restrict method. Here's an example built from the one in
the Help file:

Public Sub ContactPhoneNumber()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Ite ms
Set myItems = myContacts.Restrict("[BusinessTelephoneNumber] = '+1

(555)
555-1234'")
For Each myItem In myItems
If (myItem.Class = olContact) Then
Debug.Print myItem.FullName
End If
Next
End Sub

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Angus Comber" wrote:

Hello

In Outlook I can use the Find Items feature to find a contact.

Eg I can look for 01222 & 456789

How can I do the same using VB?

Angus





  #4  
Old April 7th 06, 04:05 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Find a contact by telephone number

You can't use wildcards in the search, so you'll have to perform multiple
searches for each variation of known phone number formats. A pain, I know.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Angus Comber" wrote:

Thanks that's really helpful. However, the problem is most people enter a
telephone number with spaces. In UK a London telephone number might be 020
8888 9999

I get from a phone system 022088889999

Any ideas on how I can do a generic search which eg ignores spaces. Or
ideally where I can ignore spaces, brackets, hyphens?

Angus

"Eric Legault [MVP - Outlook]" wrote in
message ...
You can use the Restrict method. Here's an example built from the one in
the Help file:

Public Sub ContactPhoneNumber()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Ite ms
Set myItems = myContacts.Restrict("[BusinessTelephoneNumber] = '+1

(555)
555-1234'")
For Each myItem In myItems
If (myItem.Class = olContact) Then
Debug.Print myItem.FullName
End If
Next
End Sub

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Angus Comber" wrote:

Hello

In Outlook I can use the Find Items feature to find a contact.

Eg I can look for 01222 & 456789

How can I do the same using VB?

Angus






 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Annoying telephone number formatiing Alphonse Outlook - Installation 4 April 1st 06 06:24 AM
Can I extend the number of names in the find a contact section? JB's Fitness Outlook - Using Contacts 0 March 30th 06 03:11 AM
Outlook should let me configure telephone number formatting. KC Outlook - Using Contacts 3 February 2nd 06 04:35 PM
show primary telephone number first? Brian Tillman Outlook - Using Contacts 0 January 11th 06 02:36 PM
show primary telephone number first? MarioFromBelgium Outlook - Using Contacts 0 January 11th 06 01:18 PM


All times are GMT +1. The time now is 07:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.