Sort form records by field looked up in another table


G

Green Biro

Can I sort a datasheet form by the values shown in a combo box automatically
after an update, addition or requery?

When in the form (it's actually a subform), I click on the header of a
column that contains a combo box then click on the A-Z icon and my records
conveniently get sorted by the value dispayed in the combo box rather than
the actual value that is going in the underlying table. I just want to be
able to automate that action.

More info: My main form points to my class table, my subform shows the
records that match in my StudentClass table. My datasheet has a combo box
that looks up the full student name in the Student table even though
obviously only the student keynumber is stored in the StudentClass table.
My Student table is a 'linked' table. It points to a csv file.

As I say everything works perfectly. I just need to know the VBA that I
need to automate the manual sort that I can do. My efforts to use
'me.orderby' sort by the keynumber rather than the student name.

Thanks in advance for any assistance.

GB
 
Ad

Advertisements

J

John White

Ideally, you want to control the sorting of the datagrid with your Record Source, having at the end ORDER BY and the name of the field holding the text selected (by Primary Key I presume) and then ASC. Then, when a new record is added, do a Me.Requery. You could also do it in the combo box's AfterUpdate event.

SELECT ...
FROM ...
WHERE ...
ORDER BY TextFieldName ASC

Submitted via EggHeadCafe - Software Developer Portal of Choice
Review of DevExpress DXperience Control Suite
http://www.eggheadcafe.com/tutorial...w-of-devexpress-dxperience-control-suite.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top