Dynamic Crosstab Report (1 Viewer)

thmsjlmnt3953

Registered User.
Local time
Today, 23:48
Joined
May 20, 2014
Messages
120
Hi,

Would anyone be able to give me some step by steps in creating a dynamic crosstab? i have 2 tables one is pickstats - empid,lines,hours - the other table is tblemp - empid,fname,lname.
i query this to give TSM:[fname]&" "&[lname], LPM:[Lines]/[Hours]/60 - i can create a crosstab from here however its getting it in a way so i can select 2 dates start and end - no more than 31 (1 month) and getting it to show in a report?

I've tried using all the guides online and just cant get any to work at all.
 

jdraw

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Jan 23, 2006
Messages
15,378
I found this via Google using this search parameter
Code:
[COLOR="Purple"][B][I]msaccess dynamic crosstab report example[/I][/B][/COLOR]
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:48
Joined
Feb 19, 2013
Messages
16,605
to limit the records returned you would use a criteria as for any query i.e. something like

WHERE eventDate between [Enter Start Date] and [Enter End Date]

To be dynamic and appear in a report is a different matter. If you can pivot on a value which is common to all requests - e.g. Day1, Day2 etc then that is fairly straightforward. However if you need dates 1/1/2014, 2/1/2014 etc, you would need to have in your report controls named say Day1, Day2 etc and some code to assign each of the pivoted column names to these control controlsources
 

Minty

AWF VIP
Local time
Today, 23:48
Joined
Jul 26, 2013
Messages
10,371
If you use parameters in a crosstab remember you have to declare them in the query designer using the parameters properties window otherwise it just doesn't work!
 

thmsjlmnt3953

Registered User.
Local time
Today, 23:48
Joined
May 20, 2014
Messages
120
Hi,

Rather than start this in my main db ive taken 2 tables from this with mock data and began to build this so its easy to incorporate back into my main, i've got quite far in = its just the dynamic field name's i need to finish now which im stuck with, ive uploaded a copy of my DB so far if anyone can help me with

View attachment Database14.accdb
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:48
Joined
Feb 19, 2013
Messages
16,605
As explained in my previous post

To be dynamic and appear in a report is a different matter. If you can pivot on a value which is common to all requests - e.g. Day1, Day2 etc then that is fairly straightforward. However if you need dates 1/1/2014, 2/1/2014 etc, you would need to have in your report controls named say Day1, Day2 etc and some code to assign each of the pivoted column names to these control controlsources

To be able to use a crosstab as a form or report recordsource, you need to specify the column headings - to do this, open the crosstab and display the propertysheet for the top half of the query form as here


However the problem you have is that you don't know until the date range is specified by the user is what those column headings need to be, so you'll need some code to modify and save the crosstab query before opening the report.

At which point you have the next problem, which is that the controlsource for the controls relating to these columns also need to change and perhaps some hidden if the number of controls exceed the number of columns.

Which is the third issue - how many controls are you going to have? - what if the user only wants to see a few columns one day, then a whole year, the next.

These can be overcome, but you need to be clear about the rules for the user - perhaps there is a maximum number of columns to display - the maximum width of a form is 22 inches, so there is a 'natural' limit dependant on the width of the control in any event.

You need to decide a naming convention for the fields and controls - one that typically increments by 1 - e.g. Day1, Day2 to make automation of the process easier but is easily translateable back to the original value if required (for the header labels captions) - a simple trick I use is require the user to select a year and month, then the report has a maximum of 31 columns, numbered 1-31, or they select a year and the see 12 columns, one for each month - the others being hidden. Or you can do weeks - 52/53 columns

As said, this is doable, but decide what you want before determining the solution.

You may want to investigate using a pivot form before going down the crosstab route - initially base it on your first query, but remove the parameters looking at frmStats. There isn't a pivot report, but you can add a pivot form as a subform to a report
 

Attachments

  • Capture.JPG
    Capture.JPG
    36.5 KB · Views: 831

thmsjlmnt3953

Registered User.
Local time
Today, 23:48
Joined
May 20, 2014
Messages
120
Hi,

Apologies for the delay in reply, ive been off work and not really upto doing much DB work.

If you have a look at my attached file above, ive got the dynamic part working, however its only showing me the first record across the dynamic 'fields' and i was wondering how to get it to show the rest, i think it lies in the VBA behind the report?

Tom
 

Users who are viewing this thread

Top Bottom