Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2010, 06:47 AM
Authorized User
 
Join Date: Mar 2006
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default CrossTab Query Issue - Where Condition

Hiya folks!

I am having a minor issue with the following CROSSTAB QUERY:

TRANSFORM First(BasicStatistics01.Measurement) AS FirstOfMeasurement
SELECT BasicStatistics01.Category
FROM BasicStatistics01
WHERE (((Format([MeasurementDate],"yyyy"))=2010))
GROUP BY BasicStatistics01.Category
ORDER BY Format([MeasurementDate],"mmmm yyyy")
PIVOT Format([MeasurementDate],"mmmm yyyy");


The above is working beautifully - so whenever I change the year, for example, from 2010 to 2009, the report adjusts to show me the months for that specific year. The above gives me something similar to the following type of report:

-------------------------January 2010--------February 2010--------March 2010--------
Measurement------10---------------25-----------------55

But if I change the WHERE line to:

WHERE (((Format([MeasurementDate],"yyyy"))=[Forms]![frmSelectYear]![SelectYear]))

so that it would be equal to the year inputted in a separate form, I get the following error:

"The Microsoft Office Access database engine does not recognise '[Forms]![frmSelectYear]![SelectYear]' as a valid field name or expression."

The field in the separate form is unbound and is configured as such:

SELECT DISTINCT Format([StatisticDate],"yyyy") AS SelectYear
FROM tblStatisticDate
ORDER BY Format([StatisticDate],"yyyy") DESC;

What am I doing wrong?

Another minor issue - the months across the top of the page are not in order from January on the left to December on the right. How can I order this by month in ascending order?

Thank you!
 
Old August 25th, 2010, 07:54 AM
Authorized User
 
Join Date: Mar 2006
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I just figured out the solution regarding the CrossTab Query!

I created a Public Function GETYEAR:

Public Function GetYear(FormName As String, FieldName As String)
GetYear = Forms(FormName).Controls(FieldName)
End Function

And then modified the line in the crosstab query to:

WHERE (((Format([MeasurementDate],"yyyy"))=GetYear("frmSelectYear","SelectYear") ))

And it worked! Now just to figure out how to sort the months on the top in the correct order.





Similar Threads
Thread Thread Starter Forum Replies Last Post
CrossTab Query Issue - Where Condition Odeh Naber Access VBA 1 February 10th, 2012 05:55 PM
IIF Condition Issue bufanator Access 2 September 11th, 2006 09:44 AM
Crosstab Query Ben Access 7 November 22nd, 2004 06:08 AM
Crosstab query Berni016x SQL Server 2000 2 September 17th, 2004 10:43 AM
Crosstab query vladimir Access 1 December 1st, 2003 04:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.