Results 1 to 13 of 13
  1. #1
    khartoum is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Location
    Liverpool
    Posts
    23

    Angry Report in alpha order

    Hi all, i have a query which returns sales in months in the correct (sql below) calendar order but my report stays in aplha order, does anybody know how i can resolve this

    SELECT Format([tblsales].[orderdate],'mmm yyyy') AS [Month], Sum(tblsales.VAT) AS SumOfVAT, Sum([quantity]*[tblproducts.productprice]+[vat]) AS total, Sum(tblsales.Discount) AS SumOfDiscount, Sum(tblsales.[Shipping&Delivery]) AS [SumOfShipping&Delivery]
    FROM tblProducts INNER JOIN tblsales ON tblProducts.ProductCode=tblsales.ProductName
    WHERE (((tblsales.OrderDate) Between [Forms]![frmreports]![datefrom] And [Forms]![frmreports]![dateto]))


    GROUP BY Format([tblsales].[orderdate],'mmm yyyy'), tblsales.ProductName, tblsales.Quantity, tblProducts.ProductPrice, Format([tblsales].[orderdate],'mm')
    ORDER BY format([tblsales].[orderdate],'mm');

    many thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    The report's sorting has to be set up in Sorting and Grouping, on the ribbon.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    khartoum is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Location
    Liverpool
    Posts
    23
    i thought it was that simple, but i have tried; sorting snd grouping in calendar order is not an option on reports so if i'm missing something, pleasegive me the exact solution, i'll be eternally grateful
    cheers

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Add 2 columns to your query Month([tblsales].[orderdate]) and Year([tblsales].[orderdate]) Sort on those 2 fields but display the formatted field. (You can eliminate the year field if you're 100% sure the date range will always be within the same year)

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You should be able to use the same expression you use in your SQL.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Unfortunately Paul, That doesn't work as it sorts it via Alpha so the sort comes up April, August, December, feburary, January, July, June, March, May, November, October, September. Unless there's something new in Access 2010. You have to sort by the month Number for it to be correct.and if the report crosses years you have to include the numeric year for the sort.

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Forgot to mention that the year should come first in the sort order.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Quote Originally Posted by RayMilhon View Post
    Unfortunately Paul, That doesn't work
    What exactly doesn't work? If this sorts correctly in the query, it should sort correctly in Sorting and Grouping:

    format([tblsales].[orderdate],'mm')
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Paul normally I would agree with you. However, it's been my experience that as soon as you put a group or sort in the report. That supersedes the sort in the query. This may have changed in 2010 but that's what I've found in previous versions. In 2007 I had a report for a Hospital. The Report Calculated Admits, Length of Stay By Month, by Healthplan. The query grouped by Healthplan, Month (date formatted as mmm yyyy) with a sort on Month (formated as mm), counted the total admits and and summed the length of stay calculated as days between admit date and discharge date. If the admit date was say feb 27 and the discharge date was march 2 then Feb got 2 days and March 1 because the total length of stay was 3 days. Feb 27, 28, march 1 are counted since discharge was feb 2 that day was not counted. The query worked perfectly and sorted exactly how I wanted it. When I put the query into the report and grouped on healthplan the sort order ended up being as I stated earlier. April, August .... I had to include the numeric month and year and sort within the report on those 2 values to get the report to display correctly.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    In my experience, you HAVE to set the Sorting and Grouping in the report; it will not necessarily follow the sorting in the query (it may, but I never count on it). That said, I don't think you're following me. The OP's expression from the query will sort on the numerical month, and I simply said to use the same expression in Sorting and Grouping, which should also sort on the numerical month. Yes, I could make a case for adding the year, but if it worked as desired in the query it will work the same in the report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    You're right, I wasn't following you. What was confusing me is that if you look at the poster's query the ORDER BY format([tblsales].[orderdate],'mm') Is not included in the Select clause so it is not available in the report to sort on. Which is what I was trying to get across it has to be included in the select.

  12. #12
    khartoum is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Location
    Liverpool
    Posts
    23
    Hi chaps, interesting discussion, i tried asolution as below:
    base the grouping on the constructed month number field, Format([tblsales].[orderdate],'mm'). Don't even need field in a textbox on report. Can calculate that value in the query and reference that field name or in the report Group/Sort/Total settings with the Group By on expression.
    it works fine but once i cross into the next year, it then sorts by 'mm' - i am assuming Ray that is where the sorting by yyyy first coes in - is that right?
    ps thanks for input chaps!

  13. #13
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Yep, that's exactly correct.

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

Similar Threads

  1. Acess vs Alpha Five
    By afc in forum Access
    Replies: 5
    Last Post: 03-20-2012, 11:42 AM
  2. Order Report by Textbox Value
    By alyon in forum Access
    Replies: 6
    Last Post: 07-29-2011, 11:10 AM
  3. Order Summary Report
    By ryonker in forum Reports
    Replies: 1
    Last Post: 01-10-2011, 09:15 PM
  4. Recordset not showing alpha-numeric entries
    By rayhawk in forum Access
    Replies: 9
    Last Post: 10-29-2010, 08:15 AM
  5. Purchase Order Report
    By jordanturner in forum Forms
    Replies: 1
    Last Post: 10-13-2010, 10:53 PM

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