Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with crosstabs 2

Status
Not open for further replies.

drkhelmt

Programmer
Jun 15, 2004
86
0
0
US
This should be a simple deal but I can't seem to figure it out. Any help is appreciated.

I have 2 queries-

productionWork:
Code:
SELECT production.productionDate, employee.name, clProduction.hours
FROM production INNER JOIN (clProduction INNER JOIN employee ON clProduction.employeeID = employee.employeeID) ON production.productionID = clProduction.productionID
WHERE (((production.productionDate) Between [Forms]![getReport]![from_txt] And [Forms]![getReport]![to_txt]));
and
productionWork_crosstab:
Code:
TRANSFORM Sum(productionWork.hours) AS SumOfhours
SELECT Format([productionDate],"mmmm") AS [month], Sum(productionWork.hours) AS totalHours
FROM productionWork
GROUP BY Format([productionDate],"mmmm")
PIVOT productionWork.name;

When I run productionWork, all is well. No errors. When I run productionWork_crosstab I get "The Microsoft Jet database engine does not recognize '[Forms]![getReport]![from_txt]' as a valid field name or expression."

If I change production work to:
Code:
SELECT production.productionDate, employee.name, clProduction.hours
FROM production INNER JOIN (clProduction INNER JOIN employee ON clProduction.employeeID = employee.employeeID) ON production.productionID = clProduction.productionID
WHERE (((production.productionDate) Between #1/1/2006# And #1/18/2006#));
all runs well. How can I change it to use the dates I have on my form?

Any help is appreated. Thanks,


Andrew
a.k.a. Dark Helmet

"What's the matter Colonel Sandurz? Chicken?
 
The CrossTab will not work if the base query has "WHERE" condition which refers to a form value.

You can make the base query to Create a dummy table and use the dummy table in CrossTab Query.

Code:
SELECT production.productionDate, employee.name, clProduction.hours INTO Temp 
FROM production INNER JOIN (clProduction INNER JOIN employee ON clProduction.employeeID = employee.employeeID) ON production.productionID = clProduction.productionID
WHERE (((production.productionDate) Between [Forms]![getReport]![from_txt] And [Forms]![getReport]![to_txt]));

Code:
TRANSFORM Sum(Temp.hours) AS SumOfhours
SELECT Format([productionDate],"mmmm") AS [month], Sum(Temp.hours) AS totalHours
FROM Temp
GROUP BY Format([productionDate],"mmmm")
PIVOT Temp.name;

Regards,
 
You can use a criteria from a form control or parameter in crosstabs. All you have to do is set the query parameter data type:
Query=>Parameters
[Forms]![getReport]![from_txt] Date/Time (or whatever)

You also generally don't have to enter parameter data types if you specify the Column Headings.

Creating a temporary table is a waste of resources.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I agree with dhookom,
Thanks dhookom, I realise my mistake too.
Drkhelmt - Follow dhookom's method, It is the correct way and more effecient than the method I suggested.

Regards,

 
Thanks for the response.

It worked.... kinda.

Now I don't get any fields in the field list for the reports. I can run the queryies just fine and get the data needed, however, when I run the report, I get:

"The Microsoft Jet database engine does not recognize '' as a valid field name or expression."

Here is the query behind the reports:
Code:
SELECT otherWork_crosstab.*, productionWork_crosstab.*
FROM otherWork_crosstab, productionWork_crosstab;

If I delete all bound text boxes on the report it runs, but with no data (of course).

Any thoughts?

Andrew
a.k.a. Dark Helmet

"What's the matter Colonel Sandurz? Chicken?
 
Nevermind.... my mistake. I changed the querynames but did not change the data in the countrol sources.

I still don't get anything in the field list, but I guess that probably has to do with the crosstabs being dynamic in columns.

Thank you for the answers!

Andrew
a.k.a. Dark Helmet

"What's the matter Colonel Sandurz? Chicken?
 
Consider entering all possible [Name] values into the Column Headings property.

You do realize that name is a poor name to give to a name property of any object since every object has a name property.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top