Order of Records in a Combo Box

JWalcott

New Member
Joined
Jan 25, 2003
Messages
34
The primary key of the table from which the combobox data is provided is an automated number. The table contains first and last names. Although the records need to be in the alphabetical order of last names, the Last Name cannot be the primary key as there are duplicate names. How can I get the names in the combo box to appear in alphabetical order???

Any help would be appreciated.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

Go into form design view and right-click your combobox and choose Properties. This will bring up the properties window. Look for the Row Source which will contain an SQL statement something like this:-

SELECT MyTable.ID, MyTable.LastName, MyTable.FirstName FROM MyTable;

Add an ORDER BY clause at the end of this statement (before the ; ) specifying that you wish to sort by LastName then FirstName e.g.

SELECT MyTable.ID, MyTable.LastName, MyTable.FirstName FROM MyTable ORDER BY MyTable.LastName, MyTable.FirstName;
 
Upvote 0
I use some different approaches. One simple solution is to use a query as the combo box source. You can do all the sorting you like there. Unless told otherwise, the combo box will display records as sorted in the table or query. In complex situations, you can even use a query as the source for another query!

Another approach I use when it makes sense to, is to add another field to the table, format it as integer, and enter numbers in the order I want the combo list sorted. Works every time. Most helpful for small lists that don't change much.

For some larger tables, I copy all the data into Excel, quickly add sequential numbers, delete all the records from the Access table, then use Paste-Append to put the data base. (Make a backup copy of the table first!!)

Let us know how it turns out :)
 
Upvote 0

Forum statistics

Threads
1,221,574
Messages
6,160,602
Members
451,657
Latest member
Ang24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top