Results 1 to 2 of 2
  1. #1
    jlk is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Location
    Australia
    Posts
    11

    Updating monthly data with report that always displays the 'last 12 months' in order

    I have a report that shows employees names as a grouping, and in the detail section displays data from a crosstab which breaks up departments and sales totals per month. The column headings are all the last 12 months in order and row headings of departments.

    What I'm stuck on is every month I have to manually change the data source for the text boxes to move the months over. I also have to change the labels to match.

    So the first text box was Oct 2012, second Nov 2012 and so on. I then change the first box to Nov 2012 second to Dec 2012 and so on.



    I am looking for a solution where maybe I can put vba in the datasource for the first box to collect the data from the specific month that I wish to start on the table. The queries that the report is collecting the data from updates each month to reflect the correct months for the report. However when running the report it presents with the error due to not recognising eg: Oct 2011, as this month was in the last report but no longer in the current query as it now has Nov 2012 (being 12 months of data to date).

    If anyone can assist or need more info to assist please let me know.

    Thanks in advance
    Attached Thumbnails Attached Thumbnails access report design view.jpg  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Stabilizing a crosstab to run perpetually in a report can be tricky, especially when pivoting on date data and the report needs to be dynamic for progressive reporting periods. Sometimes the solution is a crosstab that isn't a pivot query. The crosstab fields are created by expressions. No VBA is involved in this approach. Start with this sample data:
    EmpID Dept SaleDate Sales
    11 Mens 2/15/2012 200
    11 Womens 2/15/2012 300
    12 Mens 2/15/2012 100
    12 Children 3/15/2012 50
    11 Children 4/15/2012 500
    12 Mens 5/15/2012 400

    And this query:
    SELECT EmpID, Dept, Sum(IIf(Format([SaleDate],"mmmyyyy")=Format([enter date],"mmmyyyy"),[Sales],0)) AS MoYr1, Sum(IIf(Format([SaleDate],"mmmyyyy")=Format(DateAdd("m",1,[enter date]),"mmmyyyy"),[Sales],0)) AS MoYr2
    FROM Table1
    GROUP BY EmpID, Dept;

    [enter date] is an input parameter prompt but could instead be a reference to a textbox on a form. Then labels on the report could be textboxes with an expression to calculate the text to display as a caption. The expressions could reference the form textbox:
    =Format(Forms!formname!textboxname, "mmm" & "(" & Year(Forms!formname!textboxname) & ")")
    =Format(DateAdd("m",1,Forms!formname!textboxname), "mmm" & "(" & Year(DateAdd("m",1,Forms!formname!textboxname)) & ")")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 6
    Last Post: 11-10-2012, 09:49 PM
  2. Replies: 1
    Last Post: 09-21-2012, 03:31 PM
  3. Replies: 27
    Last Post: 08-14-2012, 09:05 AM
  4. Replies: 9
    Last Post: 04-27-2011, 05:04 PM
  5. How to report data in fical year order
    By gemini2 in forum Reports
    Replies: 1
    Last Post: 05-27-2006, 06:26 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