View Single Post
  #14  
Old December 5th, 2006, 12:20 AM posted to microsoft.public.access.reports
John Spencer
external usenet poster
 
Posts: 110
Default SELECT Statement in a Report

RESPONSES in line. Sorry, but as a volunteer, I can't always get on line to
answer further questions.

chickalina wrote:

I am trying to do this in a report. Let me see if I have this correct:

1. I do not need the crosstab query I've created.

No, you probably do need the crosstab as the source of the report, but it sounds
as if you may need to modify it so you can specify your period start and the
names of the year columns.

2. for the "name" for the 5 years will be Year 1, Year 2, etc. and they will
be in the page header. and take the year from the calculations in the detail
section.

You would have unbound controls in the report's page header or in a group header
for the column labels. You would use a VBA formula in the format event of the
relevant section to assign the value to the control.

Assuming that you were getting the start year from a form, you could use
something like the following to assign the value to the control

txtControlYear1 = Forms![FormGetYear]![TxtYearNumberControl] + 0
txtControlYear2 = Forms![FormGetYear]![TxtYearNumberControl] + 1
txtControlYear3 = Forms![FormGetYear]![TxtYearNumberControl] + 2
txtControlYear4 = Forms![FormGetYear]![TxtYearNumberControl] + 3
txtControlYear5 = Forms![FormGetYear]![TxtYearNumberControl] + 4

3. The details section will hold the actual calculations for every idea,
with a select statement, by year.

No, the details section would be the fields (columns) from the crosstab



4. In order to calculate certain characteristics (some ideas, some are cash,
some are both) at the end of each country, this can be done with a select
statement in which section... this is what I don't get. I've tried the code
in the details section, page header, page footer, you name it. It doesn't
work. I checked and rechecked the code.

And here you have lost me. Your sample showed Idea and a Count(?) of the idea.
Now you are introducing characteristics and cash?


So, if I am correct... where do I find all this glorious code!

Thanks for your help John, I appreciate it!
M

"John Spencer" wrote:

You seem to be asking multiple questions at once. I would suggest that we
try to solve one question at a time.

1) Post the SQL of the crosstab query for specific advice on how you might
modify it to get just five years. If you want to vary the number of years
then we will hope that Duane Hookom is around and can point you to some
sample databases on how to do this.

2) Instead of hard coding the years, use relative column names like Year1,
Year2, Year3, Year4, and Year5. You can use code on a form or in a report
to change the captions on labels or the control source of unbound text
controls to show the year numbers.

3) If you have the start year and you are always going to have 5 years, you
don't need to ask for the end year. Plus if you are limiting the report to
5 years and the user enters 2005 to 2014 they are going to be confused when
they only get 2005 to 2009 data in the report.

Are you doing this on a form or are you doing this in a report?


"chickalina" wrote in message
...
John,
Also, I have a form that looks like thiswhich is only supposed to be a 5
year projection)

Country
Local
2007 2008 2009 2010 2011 Total
Idea 5 5 5 5 5 25

State
Idea 4 4 4 4 4 16

The yearly totals are taken from a Crosstab Query, but the years are hard
coded.
If I want 2012 included, I have to go back into the query and add that
column. How can this be done automatically?

Because I want to create a pop up form for the report where they can put a
start and end date so the report only shows the 5 year window. How do I
set
up the report fields?

OR, is this too involved?

P.S. this is also the same report where I'm putting the SELECT statement
in
the footer.

"chickalina" wrote:

John,
Thanks for the help... I'm going rename Value to QtrValue or something
like
that... but for now, the code still does not work. Might that be because
of
the placement on the report? It's in the footer now to give apply this
equation to each section.
I've tried with the brackets and without.
Thanks.

"John Spencer" wrote:

It looks as if you have ther brackets incorrectly placed.

SELECT [tbl_Ideas_Bank].[IdeaID]
, [tbl_Ideas_Bank].[BenefitType]
, [tbl_Quarter].[QtrEndDate]
, [tbl_Quarter].[Value]
FROM [tbl_Ideas_Bank], [ tbl_Quarter]
WHERE ((([tbl_Ideas_Bank].[BenefitType])="ETR & Cash") AND
((tbl_Quarter.QtrEndDate) Between #1/1/2007# And #12/31/2007#)));

And since you really don't need the brackets becuase your table and
field
names contain no spaces. That could be rewritten as
SELECT tbl_Ideas_Bank.IdeaID
, tbl_Ideas_Bank.BenefitType
, tbl_Quarter.QtrEndDate
, tbl_Quarter.Value
FROM tbl_Ideas_Bank, tbl_Quarter
WHERE tbl_Ideas_Bank.BenefitType="ETR & Cash" AND
tbl_Quarter.QtrEndDate Between #1/1/2007# And #12/31/2007#

I would be wary of using "Value" as a field name, since it is a
reserved
word in Access, but you are probably OK in the query. Elsewhere the
use of
the word Value could cause naming conflicts since most controls have a
value
property.

"chickalina" wrote in message
...
What's wrong with this code? It keeps giving me the ?Error message,
and
when
I try to run the report, it says there's a problem. It runs in the
query
though.

SELECT [tbl_Ideas_Bank.IdeaID]![ tbl_Ideas_Bank.BenefitType],
[tbl_Quarter.QtrEndDate],[ tbl_Quarter.Value]
FROM [tbl_Ideas_Bank],[ tbl_Quarter]
WHERE (((tbl_Ideas_Bank.BenefitType)="ETR & Cash") AND
((tbl_Quarter.QtrEndDate) Between #1/1/2007# And #12/31/2007#)));

Thanks.