Rows and column headings are date fields formatted “mm/yyyy” in the crosstab query. Spans two separate years.
How to force row and column headings to sort chronologically not alpha in the crosstab query?
Looking for ideas?
TIA.
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Custom formatted date in ctab query (A2K)
You would have to use Column Headings property (Query Properties dialog) to specify sort order for the column headings since the Format function results in a text string. In SQL these values will equate to the values listed in the optional IN clause following the PIVOT clause. Example:
TRANSFORM Nz(Count([OrderID]),0) AS [Orders Count]
SELECT Orders.CustomerID
FROM Orders
GROUP BY Orders.CustomerID
PIVOT Format([OrderDate],”mm/yyyy”) In (“01/1997″,”02/1997″,”03/1997″,”04/1997″,”05/1997″,”06/1997”)
This example from NorthWind database. If you don’t want to manually enter the fixed column headings or they may often change, you can use VBA to generate the SQL statement dynamically.
HTH
A while back I posted some code that showed how to set crosstab column headings dynamically, but that code would not work in this case because the formatted date column headings make things a bit more convoluted. The attached sample database, using revised code, demonstrates how this can be done using VBA to dynamically create a new crosstab query with formatted date column headings sorted in chronological, not alphabetical order. Date range for query based on user input. This example uses the Orders table from NorthWind.mdb for demonstration purposes. To test open frmXTAB form, all code is in form module. (It was too lengthy to post here.) If using this code in your own project, make sure to set reference to “Microsoft DAO 3.6 Object Library.”
HTH
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications