Results 1 to 4 of 4
  1. #1
    Williams485 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    42

    Crosstab Report using 'last 6 weeks' as column headings

    Hello Access Forum,



    I've created a report that has a crosstab query as its record source:

    Code:
    TRANSFORM Count([ContHist Static].RECID) AS CountOfRECID
    SELECT Lookups.DESCRIPTION
    FROM [ContHist Static], Lookups
    WHERE ((([ContHist Static]![ACTVCODE])=[Lookups]![FLD_VAL]) AND (([ONDATE]-DatePart("w",[ONDATE])+2) Between (Date()-42) And Date()))
    GROUP BY Lookups.DESCRIPTION
    ORDER BY [ONDATE]-DatePart("w",[ONDATE])+2 DESC 
    PIVOT [ONDATE]-DatePart("w",[ONDATE])+2;
    this is what the query gives me:

    DESCRIPTION 23/02/2015 16/02/2015 09/02/2015 02/02/2015 26/01/2015 19/01/2015
    Item 1




    2
    Item 2
    1 2 2 7 8
    Item 3 1 6 2 1 2 1
    Item 4 6 22 10 7 5 2
    Item 5 6 22 10 7 5 2
    Item 6



    1 1
    Item 7

    1

    1
    Item 8
    2 1 4 2 3
    Item 9
    3 2 1 3 1
    Item 10
    2
    2

    Item 11



    1
    Item 12 1 6
    2
    1
    Item 13




    1

    I created the report by simply 'dragging' the query onto the report in design view. This worked fine until the date changed: it fixed the column headers and control sources of the text boxes and doesn't update with the query (i.e. it fixed the right-most column as 12/01/15 but that is no longer within the scope of the query and gives errors).

    How can I set the report so that the controls (and their labels) adjust according to what the query actually shows? (I've tried looking for solutions to this but I don't understand any of what I have found).

    Many thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I think you have to include something along these lines.
    Date() and DateAdd("ww",-6, Date())

    where Date is today and DateAdd("ww",-6, Date()) is 6 weeks earlier.

    But you know your situation better than the readers do.
    Good luck

  3. #3
    Williams485 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    42
    Thanks, Orange. Can you be clearer as to where I need to include your suggestion? Is it the column headers or the value fields on the report?

  4. #4
    Williams485 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    42
    Solved: I ended up changing both the label and control source of the text boxes using VBA:

    Code:
    Private Sub Report_Load()
    Me.lblWk1.Caption = CStr(Date - DatePart("w", Date) + 2)
    Me.lblWk2.Caption = CStr((Date - DatePart("w", Date) + 2) - 7)
    Me.lblWk3.Caption = CStr((Date - DatePart("w", Date) + 2) - 14)
    
    Me.txtWk1.ControlSource = CStr(Me.lblWk1.Caption)
    Me.txtWk2.ControlSource = CStr(Me.lblWk2.Caption)
    Me.txtWk3.ControlSource = CStr(Me.lblWk3.Caption)
    End Sub

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

Similar Threads

  1. Dynamic Dates in Crosstab Column Headings
    By air3jxt in forum Queries
    Replies: 5
    Last Post: 03-05-2014, 05:57 PM
  2. Dynamic crosstab report sorting headings & dlookup
    By chrisangk in forum Programming
    Replies: 9
    Last Post: 01-14-2013, 02:37 PM
  3. Dynamic Headings on Multi Column Report
    By EddieN1 in forum Reports
    Replies: 7
    Last Post: 08-19-2012, 02:39 PM
  4. Replies: 4
    Last Post: 07-27-2012, 07:04 AM
  5. Setting crosstab headings dynamically
    By dougie in forum Queries
    Replies: 3
    Last Post: 01-18-2012, 12:47 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