I am doing a little research on this topic, and I can not find a single suitable solution, or what is explained quite well for me.
If you've ever created a crosstab query in Access, you know that by default, Access sorts your columns in alphabetical order. You can change this order by going to the Properties dialog and entering Column Headers in the order you prefer. This is a real pain, but, as one respondent said on another site: "This is only pain!"
Well ... this is not the case if your columns are dynamic. In my case, I have a second column in the table that contains the column headers that I would like to use in this field for sorting. I guess I could add the details of the sort column before the description column (which was suggested elsewhere), but I don’t feel that this is the most elegant way to solve the problem. This is especially a problem since the sorting information is system data and is useless to the end user of the crosstab.
Does anyone know of a solution to this problem? If so, can you describe the steps for sorting the dynamic columns of a crosstab?
I think the problem is constant in all versions of Access that are widely used (Access 2003+), but in case it matters, I use Access 2010.
UPDATE
Here are some very simplified examples of data that help express the problem. There are several other difficulties surrounding my live script, but this dataset certainly makes sense.
Table # 1 This is where the headers come from. Key is the sorting for the order of the columns, and Descriptions is the displayed title in the crosstab.
+---------+---------------------------------------+ | Key | Descriptions | +---------+---------------------------------------+ | Kfsg2E | Hey, this is accounting code X! | +---------+---------------------------------------+ | abR3 | This is yet another accounting code! | +---------+---------------------------------------+ | Gruu! | Yet another accounting code | +---------+---------------------------------------+
Table # 2 This P_Key + F_Key data P_Key + F_Key is unique, and two are the primary key in the table.
+---------+---------+-------+ | P_Key | F_Key | Value | +---------+---------+-------+ | 1001 |Kfsg2E | 1.0 | +---------+---------+-------+ | 1001 |abR3 | 1.1 | +---------+---------+-------+ | 1001 |Gruu! | 1.2 | +---------+---------+-------+ | 1002 |Kfsg2E | 2.0 | +---------+---------+-------+ | 1002 |abR3 | 2.1 | +---------+---------+-------+ | 1002 |Gruu! | 2.2 | +---------+---------+-------+ | 2001 |Kfsg2E | 3.0 | +---------+---------+-------+ | 2001 |abR3 | 3.1 | +---------+---------+-------+ | 2001 |Gruu! | 3.2 | +---------+---------+-------+
Crosstab Results They are exported to Excel for user updates.
+---------+---------------------------------+--------------------------------------+-----------------------------+ | P_Key | Hey, this is accounting code X! | This is yet another accounting code! | Yet another accounting code | +---------+---------------------------------+--------------------------------------+-----------------------------+ | 1001 | 1.0 | 1.1 | 1.2 | +---------+---------------------------------+--------------------------------------+-----------------------------+ | 1001 | 2.0 | 2.1 | 2.2 | +---------+---------------------------------+--------------------------------------+-----------------------------+ | 1001 | 3.0 | 3.1 | 3.2 | +---------+---------------------------------+--------------------------------------+-----------------------------+
This is how Access sorts these columns. However, I need it to look like this is the table below, which is sorted by key in Table #1 , not Description .
+---------+--------------------------------------+-----------------------------+---------------------------------+ | P_Key | This is yet another accounting code! | Yet another accounting code | Hey, this is accounting code X! | +---------+--------------------------------------+-----------------------------+---------------------------------+ | 1001 | 1.1 | 1.2 | 1.0 | +---------+--------------------------------------+-----------------------------+---------------------------------+ | 1001 | 2.1 | 2.2 | 2.0 | +---------+--------------------------------------+-----------------------------+---------------------------------+ | 1001 | 3.1 | 3.2 | 3.0 | +---------+--------------------------------------+-----------------------------+---------------------------------+