?
Solved

Locate a specific contact in a subfolder using VBA

Posted on 2009-04-16
5
Medium Priority
?
441 Views
Last Modified: 2012-05-06
Can anyone help me on the VBA to find and extract information on a specific contact in a subfolder within Contacts in Outlook?  I have code that will loop through all contacts, and I can actually do a check on the name using a loop, as in, if myitem.CompanyName = "Coke" then, etc etc, but this takes a few seconds to loop through my list - there must be a quicker way.
0
Comment
Question by:mjsteele001
  • 3
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 24161959
Hi, mjsteele001.

You can speed this up by using the Find or Restrict method of a folder's Items property rather than looping through all the items.  For example
Dim olkItem As Outlook.ContactItem
Set olkItem = olkFolder.Items.Find("[CompanyName] = 'Coke'")
If TypeName(olkItem) = "Nothing" Then
    'Code for whatever you want to do if no matching contacts were found'
Else
    'Code for whatever you want to do if a match was found'
End If

Open in new window

0
 
LVL 2

Author Comment

by:mjsteele001
ID: 24170559
Thanks - works great, except... how to assign the company name (coke) to a variable? - tried the usual but I can't get it to work!
0
 
LVL 2

Author Comment

by:mjsteele001
ID: 24170754
Sorted!
CompanyName = "[CompanyName] = '" & "Coke" & "'"
Dim olkItem As Outlook.ContactItem
Set olkItem = olkFolder.Items.Find(CompanyName)
If TypeName(olkItem) = "Nothing" Then
    'Code for whatever you want to do if no matching contacts were found'
Else
    'Code for whatever you want to do if a match was found'
End If

Open in new window

0
 
LVL 2

Author Comment

by:mjsteele001
ID: 24170778
Hello BlueDevilFan, thank you for your time.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24171129
You're welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question