Question : Column headings in crosstab queries   part 2

Last week Nic;o and Harfang kindly helped me with a dynamic heading problem in a report, deriving from a crosstab query.
In one of Harfang's posts he comments, "the numbers can also be used to sort the columns in a meaningful order. ... users enjoy the fact that they can reorder the columns to their liking"

The dynamic coulmn headings are working but now need help with dynamic ordering of the headings/columns.
For background have an audit database. Audit findings are "agree", "developmental" and "error".  Have a lookup table that holds these three values. Table name is RxAudit and it has two fields, ie RxAuditID (number field, holding 1 2 and 3) and RxAudit, (text field holding "agree", "developmental" and "error")

The crosstab for the report goes like this
TRANSFORM Count(BasisOfCrosstabsRequirements.AuditNumberID) AS [The Value]
SELECT BasisOfCrosstabsRequirements.AuditNumber, BasisOfCrosstabsRequirements.RxComplexity, BasisOfCrosstabsRequirements.RxType, Count(BasisOfCrosstabsRequirements.AuditNumberID) AS [Total Of AuditNumberID]
FROM BasisOfCrosstabsRequirements
GROUP BY BasisOfCrosstabsRequirements.AuditNumber, BasisOfCrosstabsRequirements.RxComplexity, BasisOfCrosstabsRequirements.RxType
PIVOT BasisOfCrosstabsRequirements.RxAuditID In ("1","2","3");

The report gets its label headings form DLookup's, like this
=DLookUp("RxAudit","RxAudit","RxAuditID = 1")

So the headings are dynamic. Change "agree" to "Well Done!" in the field RxAudit and the report heading changes to reflect this.
But how can I dynamically change the order of the headings/column data, i.e. change the report heading to read "error", "developmental", "agree"  instead of "agree", "developmental", "error" and for the heading to be sitting over the correct column data.

Thank you



Answer : Column headings in crosstab queries   part 2

Hmm, try:

' Force sort order
Set rs = CurrentDb.OpenRecordset("select SortOrder from RxAudit order by SortOrder")

rs.MoveLast
rs.MoveFirst
For intI = 1 To rs.RecordCount
  ' set corresponsing detail field
  Me("Col" & intI).ControlSource = rs("RxAudit")
  rs.MoveNext
Next intI

Nic;o)
Random Solutions  
 
programming4us programming4us