Solved

Access07 - Reliability of a CrossTab Query results in a Form's design.

Posted on 2014-01-26
3
326 Views
Last Modified: 2014-01-27
Hello All

For a particular Form I need the results of a CrossTab query.  That Ctab query will have ItemIDs as its columns and Day's total info as its rows.

Since I've never used CTab queries I wanted to know how reliable they will be in my Form or will it "blow" up if an Item all of a sudden has no info for a day when before it always had info....

EXAMPLE - My Crosstab query is based on this query's code.
SELECT qry_InfoDetails_EndofDay.BusDay, qry_InfoDetails_EndofDay.MachPollPositionID, qry_InfoDetails_EndofDay.AmtIn, qry_InfoDetails_EndofDay.EndofDay
FROM qry_InfoDetailsLastPullDate INNER JOIN qry_InfoDetails_EndofDay ON qry_InfoDetailsLastPullDate.MachPollPositionID = qry_InfoDetails_EndofDay.MachPollPositionID
WHERE (((qry_InfoDetails_EndofDay.BusDay)>=[qry_InfoDetailsLastPullDate].[MaxBusDay]))
GROUP BY qry_InfoDetails_EndofDay.BusDay, qry_InfoDetails_EndofDay.MachPollPositionID, qry_InfoDetails_EndofDay.AmtIn, qry_InfoDetails_EndofDay.EndofDay
ORDER BY qry_InfoDetails_EndofDay.BusDay, qry_InfoDetails_EndofDay.MachPollPositionID;

Open in new window


THEN...My cross tab query will pull info as:
TRANSFORM Sum(qry_LVLInfoDetailEODSinceLastPull.AmtIn) AS SumOfAmtIn
SELECT qry_LVLInfoDetailEODSinceLastPull.BusDay, Sum(qry_LVLInfoDetailEODSinceLastPull.AmtIn) AS [Total Of AmtIn]
FROM qry_LVLInfoDetailEODSinceLastPull
GROUP BY qry_LVLInfoDetailEODSinceLastPull.BusDay
PIVOT qry_LVLInfoDetailEODSinceLastPull.LVLMachPollPositionID;

Open in new window


Since my MachPollPositionID's always will be numbers 1 to 10 but if there is NO EndofDay = True records will it bomb out or is there a way in the first query I can have it put a zero (0) number in every poll position for data=today that would prevent a null query.
0
Comment
Question by:wlwebb
3 Comments
 
LVL 5

Accepted Solution

by:
Lawrence Barnes earned 500 total points
ID: 39810092
Cross tabs are great, but where there's missing data and nothing to create an expected column, the forms do crash.

You can use the NZ function to put in a zero if the value is null on the first query to handle cases of no data.

SELECT qry_InfoDetails_EndofDay.BusDay, qry_InfoDetails_EndofDay.MachPollPositionID, NZ(qry_InfoDetails_EndofDay.AmtIn,0) as AmtIn, qry_InfoDetails_EndofDay.EndofDay

Also, for the columns going on the cross tab results I always wanted the column names (fields displayed in the forms) to have the same names.  So instead of the column name being a date, I changed it to Day-1, Day-2, Day-3 so that the form fields would be stack and the user new that Day-10 was 10 days ago.
0
 

Author Closing Comment

by:wlwebb
ID: 39811949
Thanks for the suggestion.
0
 
LVL 10

Expert Comment

by:Luke Chung
ID: 39812002
Use the IN clause to require column values to avoid problems with missing data.

Here's an example of using a report to display a 12 month report for any date range: http://www.fmsinc.com/MicrosoftAccess/query/crosstab-report/index.html

The same can be done for a form.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 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…

821 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