issue with reading the value in the subreport from report

  • Thread starter Thread starter Associates
  • Start date Start date
A

Associates

Hi,

I have been trying to make the following VB code to work but with no luck.
Wonder if anyone might be able to help me out.

Me.TotNumOfStudents = Sum([Reports]![Students Report]![StudentsPerClass])

I have a report called MasterReport which has a subreport, called "Students
Report". What i want to do here is to be able to work out a total of number
of students per classroo. To do this, i need to do a sum of StudentsPerClass
that exists in the subreport, Students Report. When i run the code, it
prompts me for the value of StudentsPerClass in a Windows Dialog box.

The textbox of TotNumOfStudents is actually in the MasterReport, though.

I donot understand why it did not like it. Would it be because the subreport
has not yet been run and therefore the MasterReport can not know the value
for the textbox TotNumOfStudents?

Any help would be greatly appreciated.

Thank you in advance
 
While, it is possible to use VBA code in the Format event of the section
that contains the text box on the main report to read a total from a control
in the subreport that has already accumulated the total, you don't need code
to do this job.

If you do use code, be aware that reports are not like forms. Forms have a
current record that can be read from anywhere; reports are forward scrolling
objects where the concept of a value in the current record does not apply.

Here's the simple (and code-free) solution:
Bring the total from a subreport onto a main report
at:
http://allenbrowne.com/casu-18.html
 
It works, Allen.

Thank you very much for your help

Allen Browne said:
While, it is possible to use VBA code in the Format event of the section
that contains the text box on the main report to read a total from a control
in the subreport that has already accumulated the total, you don't need code
to do this job.

If you do use code, be aware that reports are not like forms. Forms have a
current record that can be read from anywhere; reports are forward scrolling
objects where the concept of a value in the current record does not apply.

Here's the simple (and code-free) solution:
Bring the total from a subreport onto a main report
at:
http://allenbrowne.com/casu-18.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Associates said:
Hi,

I have been trying to make the following VB code to work but with no luck.
Wonder if anyone might be able to help me out.

Me.TotNumOfStudents = Sum([Reports]![Students Report]![StudentsPerClass])

I have a report called MasterReport which has a subreport, called
"Students
Report". What i want to do here is to be able to work out a total of
number
of students per classroo. To do this, i need to do a sum of
StudentsPerClass
that exists in the subreport, Students Report. When i run the code, it
prompts me for the value of StudentsPerClass in a Windows Dialog box.

The textbox of TotNumOfStudents is actually in the MasterReport, though.

I donot understand why it did not like it. Would it be because the
subreport
has not yet been run and therefore the MasterReport can not know the value
for the textbox TotNumOfStudents?
 
Back
Top