Can't get the "sort" method to work on "AddressEntries"

B

Bernard.Luksich

This must be a simple problem but we just can't see it.

We have a Visual Basic for Applications program that is looking up
names in an address book in order to find the email address. The
program works great but is a bit slow since it is doing a simple look
up on the address entries. For each address starting at the top.

So we thought, hey, there is a "sort" method for the "addressentries"
object, let's call that and now have the list in order and the lookup
becomes much quicker...we don't have to sca the whole thing if the
entry is not there.

However, when attempting the sort method we keep getting the message...

Run-time error '-1834750 (ffee40102)'
IMAPITable::SortTable was called, which this object does not support.

What on Earth does that mean? The document we have on the "sort"
method makes no reference to this and the calling sequence seems pretty
easy. Here is the failing part of the code....'
'
' This code locates the named address list and sets up the object to
hold
' all the entries until used later to resolve addresses base on
"DisplayName"
'
Dim spAdrLsts As AddressLists
Dim spAdrLst As AddressList
Set spAdrLsts = olns.AddressLists
Set olCFAddressEntries = Nothing
For Each spAdrLst In spAdrLsts
If spAdrLst.Name = olCF.AddressBookName Then
Set olCFAddressEntries = spAdrLst.AddressEntries
Call xlMessage.AddMessage("Found the address list
entries.", "main")
Exit For
End If
Next spAdrLst
Set spAdrLsts = Nothing
Set spAdrLst = Nothing
If (olCFAddressEntries Is Nothing) Then
Call xlMessage.AddMessage("Could not find address list so must
exit.", "main", "error")
Call ReleaseEverything
Exit Sub
End If
Call olCFAddressEntries.Sort("Name", olAscending)

So what is the trick to get the address list sorted?

Thanks in advance for you help.

Bernie
 
K

Ken Slovak - [MVP - Outlook]

Does this work?

Call olCFAddressEntries.Sort("[Name]")

See the Object Browser help when in doubt.
 
W

Webmaster

Ken, thanks so much for the quick reply. No, that syntax for the sort
command does not work. Actually that is the way I first coded it.
When I got the error message I thought pershaps the braces were not
needed since the help information states "they may be used". So I took
them off.

Your comment is well taken about looking at the Object Browser since
that was the first place we notice the "sort" method applies to
AddressEntries. The MSDN site has a help page on this that is just as
brief as the regular help page and makes a comment about the different
syntax for sort as it applies to AddressEntries. But there is no
sample code for this and so after much searching we dropped the post
here.

My guess is there is something special that must be done to allow the
sort to work. Since the object is calling the MAPI TableSort somewhere
along the line in this code the underlying object has become distorted.
But the only thing we are doing is assigned the entries to an object,
and calling sort. Can the assignment throw things off? If so, then
how do you sort the AddressEntries?

Any help is appreciated.

Bernie
 
K

Ken Slovak - [MVP - Outlook]

I can't make it work here at all either. I've been informed that on a MAPI
level many address book providers don't implement things like sort and it
looks like that's what we're running into here even though it's documented.

I don't have a good alternate solution other than by using CDO or Extended
MAPI or Redemption (www.dimastr.com/redemption). You should be able to sort
or even do a type-ahead lookup type search using the later 2 API's and sort
using CDO (I haven't tested this here though).
 
B

Bernie

Ken, thanks for the really thoughtful input. I am impressed you
actually ran the code....thanks so much for doing that and confirming
what we experienced.

Your efforts are greatly appreciated.

We were just trying to create some Visual Basic for Application (VBA)
code to help with some of our processes here. Not having a sort
function just slows things down a bit but right now our database is not
so large that we can't wait for it to finish. We actually will run the
programs only a couple of times a month so what we have is probably
"good enough".

We'll take a look at the this "Redemption" thing, it has shown up in a
couple of searches we did on the subject.

I can't tell you enough how much we appreicate you time to look into
this for us.

Hope you and your family have a great Christmas.

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top