Link to home
Start Free TrialLog in
Avatar of Madmarlin
Madmarlin

asked on

Serching The Outlook Address Book Through VB

Hello experts,

Im working on a project which involves automating an email.

The users address book is very large and therefore can really wait for the full address book to load.

Is there a way of searching the addressbook content by certain criteria??

My code is as follows (currently loads all addressbook enteries, but say I wanted to list all enteries with the word 'Chris' in the name field)

Private Sub Command1_Click()
Dim oRecipiant As ListItem
Dim myAddressList As AddressList
Dim AddressEntry As AddressEntry

'Clear Address Book
lvAddressBook.ListItems.Clear
lvAddressBook.ColumnHeaders.Clear
lvAddressBook.View = lvwReport

'Add Columns
With lvAddressBook.ColumnHeaders
    .Add , , "Name"
    '.Add , , "Other Field"
End With

Set myAddressList = Application.Session.AddressLists("Global Address List")

For Each AddressEntry In myAddressList.AddressEntries
    Set oRecipiant = lvAddressBook.ListItems.Add(, , AddressEntry.Name)
Next

End Sub
Avatar of fds_fatboy
fds_fatboy

Do you mean something like this?

Dim sSearchName As String
sSearchName = "*chris*"
...

For Each AddressEntry In myAddressList.AddressEntries
    If Lcase$(AddressEntry.Name) like sSearchName then
        Set oRecipiant = lvAddressBook.ListItems.Add(, , AddressEntry.Name)
    End If
Next

...
Avatar of Ryan Chong
or try use Instr function, like:

Private Sub Command1_Click()
Dim oRecipiant As ListItem
Dim myAddressList As AddressList
Dim AddressEntry As AddressEntry

'Clear Address Book
lvAddressBook.ListItems.Clear
lvAddressBook.ColumnHeaders.Clear
lvAddressBook.View = lvwReport

'Add Columns
With lvAddressBook.ColumnHeaders
    .Add , , "Name"
    '.Add , , "Other Field"
End With

Set myAddressList = Application.Session.AddressLists("Global Address List")

For Each AddressEntry In myAddressList.AddressEntries

If Instr(1,lcase$(AddressEntry.Name), lcase$(sSearchName )) > 0 then
    Set oRecipiant = lvAddressBook.ListItems.Add(, , AddressEntry.Name)
End If

Next

End Sub
In either case the code is going to have to read the entire address book, whether it populates the LV control with all the names or a subset of the names.  If you aren't tied to using the Outlook Object Model though, then you could use CDO which has a filtering capability which'd save having to read the entire address list to find just those names that match.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_addressentryfilter_object.asp
Avatar of Madmarlin

ASKER

The comments from BlueDevilFan are correct, my problem is the number of enteries in the addresslist is ridiculously large therefore I cant loop through each one indiviually.

I am also trying to run the code the BlueDevilFan sent me without success.
I am running VB6 and the version of the CDO.DLL on my platform is 1.21 and not 1.1 so im not sure if somthing has changed, and cant seem to find any refernce to a change anywhere.

SO if proven source could be provided I am prepared to up the points.

Cheers Madmarlin
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial


Great work BlueDevilFan maybe you can help with this one, its similar and worth 400 points if quick
https://www.experts-exchange.com/questions/21158007/Obtaining-The-Mailbox-Size-Limit.html


Madmarlin
Hi, Madmarlin.

Thanks.  I saw your other question last night and spent a couple of hours researching the issue.  I can't find anything that reports the quota limits for 5.5.  The best I can offer is code that'll calculate mailbox size for 5.5 (although I can't verify that it works under 5.5 since I don't have access to a 5.5 server anymore).  If you know the quota limts, and if they are consistent (i.e. each user doesn't have a different limit), then you could caluclate the mailbox size, compare it to the limit, and take action as needed based on that comparison.  

ha ha so i didnt only waste hours myself yesterday I wasted your time aswell, im very sorry.

Yes I do believe that the limit is standard through my user base, so if you know how to check the mailbox size then I uess that would surfice.

On a persoanl note I would just like to say thankyou for you help on both this and the previous problem.

Cheers Madmarlin... ;?)
No need to be sorry.  I enjoy the challenges I find here in EE.  It keeps the mind sharp.

Ok, I'll post the code for getting the mailbox sizes shortly.  I'll post it to the other question.

You're very welcome.  
Message for BlueDevilFan...

Did you ever find the code for the other question. (see previosu comments?)

Cheers Chris
Chris,

I posted the best information I have in the other question.

-- BDF