473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

HELP: Cross-Tabs, Stored Procedures and other Wonders of the World

Hey gang,

I'm having a tough time wrapping my head around this problem. More than
anything, I'm looking for the "why" of why this isn't working.

THE SETUP:

I have a Cross-Tab query (we'll call qCrossTab) that details and sums
up the number of absences from class between a particular time frame
(for testing, I've hard-coded it into the SQL)

WHERE (((URKIDS_ATTENDANCE.CLASS_DATE) >= #8/1/1880# And
(URKIDS_ATTENDANCE.CLASS_DATE) <= #8/2/1880#))

Since the number of columns can vary (or will vary once I've added the
ability for the user to select date parameters), I've created a report
(rptAttendance) that does some formatting based on the number of
columns. The RECORDSOURCE of rptAttendance is set to qCrossTab

With this setup, everything works like a charm.

THE PROBLEM AND MYSTERY:

I am building a form that will eventually ask the user to select the
FROM and TO dates to embed into the WHERE statement above. For right
now, the form simply has one button (GENERATE REPORT) that attempts to
launch rptAttendance while passing it a STRING value (strSQL). NOTE:
strSQL below is an exact copy of the SQL from qAttendance.

Code for cbGenerateReport
================================================== =======
Private Sub cbGenerateReport_Click()
Dim strSQL As String

' builds the SQL one phrase at a time
strSQL = "TRANSFORM Sum(URKIDS_ATTENDANCE.ABSENT) AS SumOfABSENT "
strSQL = strSQL & "SELECT URKIDS_ATTENDANCE.URKIDSID,
URKIDS_ATTENDANCE.GROUPID, Abs(Sum(URKIDS_ATTENDANCE.ABSENT)) AS [Total
of ABSENT] "
strSQL = strSQL & "FROM URKIDS_GROUP RIGHT JOIN URKIDS_ATTENDANCE ON
URKIDS_GROUP.ID = URKIDS_ATTENDANCE.GROUPID "
strSQL = strSQL & "WHERE (((URKIDS_ATTENDANCE.CLASS_DATE) >= #8/1/1880#
And (URKIDS_ATTENDANCE.CLASS_DATE) <= #8/2/1880#)) "
strSQL = strSQL & "GROUP BY URKIDS_ATTENDANCE.URKIDSID,
URKIDS_ATTENDANCE.GROUPID, URKIDS_GROUP.SEASON "
strSQL = strSQL & "ORDER BY URKIDS_GROUP.SEASON "
strSQL = strSQL & "PIVOT URKIDS_ATTENDANCE.CLASS_DATE"

DoCmd.OpenReport "rptURKids-Attendance-Crosstab", acViewPreview, , , ,
strSQL

End Sub
================================================== =========
What's odd, is that when I run the report from this code (which,
technically, should have the exact same control source as just running
the report on it's own), I get the following error:

Run-time error '3637':
Cannot use the crosstab of a non-fixed column as a subquery

>From my research, it sounds as though I need to use STORED PROCEDURES
with bound columnheadings in order for a report to change it's control,
which doesn't make sense since I don't see the difference between the
two directions above...

OTHER POSSIBLE SOLUTIONS

Since I don't really get SP at the moment, I was trying to figure out a
way to get this to work.

I created a query that simply SELECT * from qCrossTab The problem
with this is that there's no way to specify the date parameters because
this is part of qCrossTab.

So, I thought, what if I could create an SQL statement and save it to
qCrossTab, overwriting what's already there. Then, I could run my
report with the proper date parameters. Question is, though, how can
I, in VB, save a query? I'm sure this isn't the best way to structure
a database, but it seems like it could be easier than fumbling around
with stored procedures.
Phew. That's all. Thanks for sticking this out. Thoughts? Suggestions?

Thanks,

Mike

Aug 8 '06 #1
1 2012
Hi Mike,

Think of a crosstab query this way. If your database is properly
normalized (no redundant data colums) then a crosstab query takes say 10
rows of data that have 3 colums (the way the computer reads - top/down)
and transforms them to horizontal - now 3 rows and 10 columns - the way
humans read it (well western humans). If you have 11 rows, you now have
11 columns after the transformation. In other words, the resultset is
not static. Subqueries have to return a somewhat static resultset. You
can have variable rows, but only fixed columns - because the computer
reads the data top/down. The fix is either to only return the same
number of columns each time, or to not use a crosstab query as a
subquery.

Without doing any deeper thinking, I would suggest to resort to good ol
fashion spaghetti code (DAO) for the fix. However, I recently had an
unsavory encounter in this NG by prescribing such a fix. So, I hope I
have identified your problem, but you are on your own for the fix.

Regards,
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Vanessa BJ | last post by:
Hi. I am an amateur Java enthusiast. I currently work as a carpenter and I moonlight on the weekends as a photographer. I'm trying to transition a career change. Which Java exam should I start...
4
by: Lorenzo | last post by:
hi you all, first of all apologies for having cross-posted this message but really i did not know where to post it. please let me know what ng you consider the most suitable for the described...
16
by: JustSomeGuy | last post by:
I have a routine that evaluates a polynomial equation that have 3 variables x,y,z of orders 1,2,3 the coefficients of the polynomial are in an array. This routine is quite slow and I'd like to...
6
by: moi | last post by:
hi, im fairly new to c++ and as part of a module at uni im learning it. i know the basics i suppose, but as our final hand-in we have to alter code we wrote for an earlier assignment to use...
2
by: P2P | last post by:
Hi I am wondering if someone know of a free cross-browsers vertical scrolling script that - is cross cross-browsers - will call the scrolling content from an external html page or from a...
6
by: mutemode | last post by:
I have this query SELECT 'bracket' = CASE WHEN income BETWEEN 0 AND 49 THEN '0-49' WHEN income BETWEEN 50 AND 99 THEN '50-99' WHEN income BETWEEN 100 AND 499 THEN '100-499' WHEN income BETWEEN...
3
by: juan brown | last post by:
I am new to usenet, need help on how to use it.
2
by: deshg | last post by:
Hey everyone, I am a php programmer originally and am just helping a friend of mine update their website that they paid a designer (well that's what he called himself!) to do ages ago. I have...
8
by: vicktorio | last post by:
Hi there, I want to design a Visual C++(or atleast a C++) USB HID GUI. The problem is that I don't know much about USB or even developing applications with it. So what I need is something to...
8
by: aeneng | last post by:
Hello everyone, I am just starting to use python in numerical cacluation. I need you to help me to see what's wrong with the following piece of codes, which computes the cross product of two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.