简体   繁体   中英

MS Access table list order is defaulted in subform

I have a subform with a table, where some fields are restricted to tables. The tables are sorted in the correct order, but when it is used in the subform, it is set to default sorting. I can't find the location of the correct place to set the sorting criteria. I tried using query instead of a table, but i could only sort either by ascending or descending (or nothing). All three options resultet in undesired order. Example of the phase being sorted as default despite the table settings:

正确的顺序

顺序错误

Suggestions?

Combo- and listboxes always contain text, thus your column is not sorted numeric.

To have a numeric sort, add a column with the number only and - in the source - sort only on that. If you don't the number separately, create it from this expression:

Val(Mid([PhaseField], 7))

As Gustav suggests, add another field to your t_Phase table, which will be the order you want this list to appear in the drop-down (make sure it is a number field):

在此处输入图片说明

Supply the numeric order:

在此处输入图片说明

In your other table, you can use the ID field from your t_Phase table by selecting it through the lookup wizard:

在此处输入图片说明

在此处输入图片说明

Move across the ID and the new "Order" field you just created:

在此处输入图片说明

Use the "Order" field as the field you want to use for sorting and make sure "Ascending" is selected:

在此处输入图片说明

Continue through the wizard:

在此处输入图片说明

Select the field that has the data you want to go in to the record of your table (I assume it's the ID field rather than the Order field, so make sure ID is selected):

在此处输入图片说明

Finish the lookup wizard and go in to Datasheet View on your table and check that the dropdown is now in numeric order. You've probably noticed a problem though as it is showing both the ID and the Order columns:

在此处输入图片说明

To hide the unnecessary Order column, go back in to Design View and click on your phase field to select it.

At the bottom should be a "Lookup" tab. Click on this and notice the Column Widths property... it's showing 2 different widths values; the first one is the ID field and the second one is the Order field. Set the Order field to 0cm to hide it. I'd then recommend setting the remaining Id field width to something that will be wide enough to show all your ID field's options. Then I'd set the List Width property to the same width.

在此处输入图片说明

8cm, for example:

在此处输入图片说明

This should result in something like the following, which is hopefully what you're after.

在此处输入图片说明

If you're not adding a lookup field to the design structure of a table, but are instead using a combo-box on a form or subform, the principle is pretty much the same; you'll just have to amend the combo-box properties from the form's Property Sheet "Format" tab instead:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM