Results 1 to 3 of 3
  1. #1
    euphonium01 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    40

    Cross-tab Query - Wrong Date Order

    Hi All. I have a small Student database, simply for records of Student Names, Addresses, Classes etc. I am trying to run a Cross-tab query for a Time Table of forthcoming Classes, FileAs (the Student) as a Row Heading, and the date of the class [ClDt] as a Column Heading. I have asked the Query to Format the class date heading as "mmm-d" (I have to make the date abundantly clear or some Students won't bother turning up!). I put some fictitious classes in to check it worked, and it did, except the Date Column Heading comes out with Apr before Mar, and if I change the formatting to "d-mmm" I get Apr-1 then Mar-25, -26, -27, Apr-4, Apr-5 etc.

    With Fortmat set "mmm-d"
    Click image for larger version. 

Name:	Format mmm-d.jpg 
Views:	12 
Size:	18.2 KB 
ID:	37964

    And Format set to "d-mmm"
    Click image for larger version. 

Name:	Format d-mmm.jpg 
Views:	11 
Size:	22.6 KB 
ID:	37965



    Query Design View
    Click image for larger version. 

Name:	Design View.jpg 
Views:	11 
Size:	25.0 KB 
ID:	37966

    From the results of different Formats, logically it would appear that by Formatting the date it is being read (and therefore sorted) as a string, rather than the date? Assuming I'm right, how would I fix this? The usual method in the Sorting box hardly makes a difference?

    Paul
    BTW: After a long long stint in hospital, it's good to be back on the Forum

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    dates like that are sorted as strings,
    so you need a different field format so sort numerically: yy-mm-dd

  3. #3
    euphonium01 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    40
    Quote Originally Posted by ranman256 View Post
    dates like that are sorted as strings,
    so you need a different field format so sort numerically: yy-mm-dd
    Many thanks ranman for your reply. I've worked on your advice for a couple of days now, but I keep running into brick walls, can I explain a few more details that may help?

    The database I am doing is a Student database for a small College, I have been doing a Crosstab Query in order to produce a Time Table for the Students. I wanted to be able to put in a 'Start Date' parameter, then have 7 days of classes, shown by Student as a Row Heading, Class Date as Column Heading, and the Course as a Value... in a Report.

    My fields are:-
    [StudentID] - Row from StudentT Table
    [FilesAs] - Row from StudentT Table
    [ClDt] - Column (Class Date) from ClassesT Table
    [LARSCode] and [Venue] - Value from CoursesT Table

    All the Tables have one to many relationships.

    Trying to follow your advice I have the following design query, which in essence works well:-
    Click image for larger version. 

Name:	Crosstab Query TT.jpg 
Views:	3 
Size:	60.3 KB 
ID:	37997

    I included clause 'IN (1,2,3,4,5,6,7)' in SQL view to achieve my 7 days.
    Click image for larger version. 

Name:	SQL View.jpg 
Views:	3 
Size:	37.6 KB 
ID:	37998

    As said, it works well and the Course, Class Time (ClTm) and Venue appear perfectly correct... when there's 31 days in the month that is!

    Where it falls down is when there's only 30 days (or 28 in February) in the month, the weekdays and dates go haywire. As an example, I requested a Start Date of 29th April (30 days in the month) the Time Table shows 7 days from the Start Date which, puts a Course (scheduled for the 2nd May) on to the 3rd May, a day late, I think it's because it has a fixed *31 in the expression, but I wasn't even close to getting anywhere near the right results unless that was included.

    I think I am understanding correctly as to why the issue arises? However, I am totally lost as to how to fix it, 3 days later I'm no further forward. I'm sure it must be possible to correct, maybe even something really simple I'm missing, maybe it means a total rejig using vba and variables instead (that, I WOULD need help with)?

    Anything you can throw my way I would appreciate, but please keep it idiot-proof, I've barely got my head around simple vba, and so far only managed this Query with your help, and following blogs on the internet.
    Many thanks... Paul
    BTW: I can easily put together the relevant objects in a small db to send if it would help? I promise to avoid Crosstab Queries in future!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-23-2018, 04:51 PM
  2. Replies: 4
    Last Post: 08-15-2017, 08:44 AM
  3. Replies: 5
    Last Post: 08-14-2015, 02:53 PM
  4. Replies: 14
    Last Post: 10-25-2014, 02:19 PM
  5. Query for latest date? what am I doing wrong?
    By Overdive in forum Queries
    Replies: 1
    Last Post: 12-18-2009, 06:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums