Solved

Crosstab Query on Form

Posted on 2013-06-06
3
487 Views
Last Modified: 2013-06-06
I need to find another option since I cannot put a crosstab query on my form. I need to show usage by item with the month/year as the column headings. I could use the ColumnHeading properties in the crosstab query but then I would have to keep adding new months to it as the year goes on. Is there any easier way to do this? If so, any ideas you care to share?
0
Comment
Question by:Lawrence Salvucci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39225266
Yes, you can force the Crosstab to  display columns that don't actually exist in your query using the PIVOT clause.  The last element of the Crosstab query looks something like:

PIVOT yourTable.yourField

You can modify that to something like:

PIVOT yourTable.yourField IN ("JAN/2013", "FEB/2013", "MAR/2013", ...)

Make sure that the spelling of the spellings in the IN ( ) clause are accurate because only those values that show up in the IN clause will be displayed.  And even if a value is not in your query results, that column will be displayed.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39225288
I'm not sure I follow you 100%. Here is the SQL for my crosstab. How would it use my date field to show the month/year and increment as the year goes on?



PARAMETERS [Forms]![frmPurchasingAnalysis1]![cbofpartno] Text ( 255 );
TRANSFORM Sum(qryPOHistory.fqtyrecv) AS SumOffqtyrecv
SELECT qryPOHistory.fpartno, Sum(qryPOHistory.fqtyrecv) AS [Total Of fqtyrecv]
FROM qryPOHistory
WHERE (((qryPOHistory.fpartno)=[Forms]![frmPurchasingAnalysis1]![cbofpartno]))
GROUP BY qryPOHistory.fpartno
PIVOT qryPOHistory.[Month/Year];

Open in new window

0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39227062
I'm not certain how your [Month/Year] field is formatted, what do those values look like.

Lets assume it is: mmm/yy

If that is the case, you could use:

PIVOT qryPOHistory.[Month/Year] IN ("Jan/13", "Feb/13", "Mar/13", "Apr/13", "May/13", "Jun/13", "Jul/13", "Aug/13", "Sep/13", "Oct/13", "Nov/13", "Dec/13")

This would give you all of the months for 2013.  If, however, your [Month/Year] column contains more than a single year, then you might have to write some code, to determine all of the [Month/Year] combinations and build that IN ( ) clause and append it to the end of your query.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question