Solved

Crosstab Query on Form

Posted on 2013-06-06
3
485 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

809 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