Tuesday, January 31, 2006

on stupid little tricks: how to sort a table by multiple columns in MSAccess

it's easy to sort by one column, you just right click on it and click sort ascending or sort descending, but to sort by more than one column (without creating a query) is a little tricky, here's what you have to do (Windows keyboard required)

you have to put the columns that you want to sort for, all together in order from left to right, you do this by clicking on the column header, and dragging it over

so if you have columns

and you want to sort by E, then by C you have to drag the E column so you have


- click on the first column you want to sort for,
- press and hold the [shift] key
- and click on the last column you want to sort

in the example, we click on column "E", press shift and click on column "C"

A B [E C] D

you then press the menu key menu key and select sort ascending or sort descending

you can now move the columns back to their original position or wherever you want to have those columns

if you close the table it will ask you to save (the layout, position of columns, columns sorted by, etc) your changes, if you do save the changes, next time you open the table it will be sorted by the columns you specified and *everything* will be the way it was when you closed it

I often create programs with complicated configurations, and I store the configuration in access table(s), yes I could use XML, but MSAccess is so much easier to program against from different languages and you have a whole GUI at your disposal to design and enter data, and tricks like this just make life easier

No comments: