filling a combo box and sorting

×

קובץ

hi!

I have a form with a combo box and want to fill it with data from a table in
access.
I was able to fill it, but I want to sort the data in the combo box
alphabeticlly.
is there any way of doing it besides bubble sort etc. ? it's a very big
table (30,000 rows). maybe I can use SQL?

thanks.
 
K

Ken Slovak - [MVP - Outlook]

How are you getting the data from Access? If you're using an ADO recordset
you could use the Recordset.Sort method. If you're using SQL you certainly
could use SQL to sort the returned recordset.
 
×

קובץ

I am using ADO recordset and trying to use the Recordset.Sort method, but
keep getting error messages. can you please show me how to use this method?

I also need to use SQL but don't know how it works in outlook. Maybe you can
write a few lines about it?

thanks,
Yonina
 
K

Ken Slovak - [MVP - Outlook]

From MSDN on Recordset.Sort:

Sort Property
Indicates one or more field names on which the Recordset is sorted, and
whether each field is sorted in ascending or descending order.

Settings and Return Values
Sets or returns a String value that indicates the field names in the
Recordset on which to sort. Each name is separated by a comma, and is
optionally followed by a blank and the keyword, ASC, which sorts the field
in ascending order, or DESC, which sorts the field in descending order. By
default, if no keyword is specified, the field is sorted in ascending order.

Remarks
This property requires the CursorLocation property to be set to adUseClient.
A temporary index will be created for each field specified in the Sort
property if an index does not already exist.

The sort operation is efficient because data is not physically rearranged,
but is simply accessed in the order specified by the index.

Setting the Sort property to an empty string will reset the rows to their
original order and delete temporary indexes. Existing indexes will not be
deleted.

Suppose a Recordset contains three fields named firstName, middleInitial,
and lastName. Set the Sort property to the string, "lastName DESC, firstName
ASC", which will order the Recordset by last name in descending order, then
by first name in ascending order. The middle initial is ignored.

No field can be named "ASC" or "DESC" because those names conflict with the
keywords ASC and DESC. Give a field with a conflicting name an alias by
using the AS keyword in the query that returns the Recordset.

SQL doesn't work with Outlook, it's working with your database and writing
code for that is the same as if Outlook isn't involved at all.
 

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