Solved

Crosstab Query on Form

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now