Solved

Crosstab Query on Form

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now