473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using the OrderBy property on an unbound ComboBox column

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

Nov 13 '05 #1
2 6137
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.
Nov 13 '05 #2
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.


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michelle Collier-Moore | last post by:
I have a form where the user selects a client name originally from a table and then proceeds to complete other details in a sub form. The users asked to see two pieces of information relating to...
6
by: P. Emigh | last post by:
By default in more recent versions, Access forms keep users' last sort request in the "orderby" property. That can slow things down considerably, especially when the last user has chosen a...
1
by: martim07 | last post by:
How do I have a textbox on a subform automatically fill in with a value after I select an item from a combo box on a form (e.g., select a product name in a combo box and have the subform populate...
9
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want...
2
by: Dutchy | last post by:
Hi there, After spending several hours trying all I could imagine and search for in Google I gave up. In a continuous form I want to sort the choosen column by clicking the header (label) of...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
2
by: Stu | last post by:
Hi, I've been working on trying to use a combo box to filter my records for a while now, and can't get it to work. Right now, I have SQL code written into IfThen statements on the afterupdate for...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
4
by: lorirobn | last post by:
Hi, I have a main menu that opens several different reports. I am adding an OrderByOn, and currently have it set up for one report with the following statements: !.OrderBy = strOrderBy...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.