Sorry, I didn't mean that I wanted to sort the values in the combo box. I
want to sort the records on my form (using either a continuous form or a
datasheet) by the unbound "description" column in a combo box on the form
(or in the datasheet.) Here's a rough text representation of what I'm
talking about
FORM
Item Number Description Category
(text box) (text box) (combo box - 2 columns)
1001 Item 1 Col1=100 Col2=CategoryName3
1002 Item 2 Col1=101 Col2=CategoryName4
1003 Item 3 Col1=102 Col2=CategoryName1
1004 Item 4 Col1=102 Col2=CategoryName1
1005 Item 5 Col1=103 Col2=CategoryName2
So..when the form loads, it is sorted by the Item Number. I want my users
to be able to sort by Category as well by clicking a command button. If I
only reference the Category column in the "OrderBy" property, it will sort
on the first column in the combo box (which is invisible to the user) and
not on the text in the second column. That's what I'm trying to alter
programatically - to sort on the text (as the "Sort Ascending" and "Sort
Descending" commands do when you manually apply the sort order.
Hope this clears up any confusion. Thanks again to anyone who might be able
to help.
Todd
"fredg" <fg******@example.invalid> wrote in message
news:1g******************************@40tude.net.. .
On Mon, 9 Aug 2004 12:16:37 -0700, Todd wrote:
Hello,
I'm curious if anyone knows of a way (if one exists) to tell a form (in
Access 2002 VBA) to sort on an unbound column of a combo box on the
form. Here's what I want to do:
A combo box on my form contains a category ID (bound column, not
visible, long integer) for the items listed on the form and a description
(unbound column, visible, string.) I can "Sort Ascending" and "Sort Descending"
on the visible description in the field represented by the combo box, but I
can't find a way to do it programatically.
I've tried using "ComboBoxName.Column(1)" as the OrderBy property for my
form but "Column(1) isn't recognized and prompts me for a value. Any
help would be appreciated.
Thanks!
Todd
As the Rowsouce property of the Combo Box, write:
Select TableName.[CategoryID],TableName.[Description] from TableName
Order By TableName.[Description];
Change YourTable to the actual name of the table.
If those are the only columns you have, set the Column Count property
to 2
Column Widths to 0";1"
Bound Column to 1
The Combo will be sorted according to the Description field, and only
the Description will show in the box. The Bound column is hidden. If
the combo is bound to a field in the table, it is the hidden
CategoryID that will be stored in the table (which is correct).
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.