Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / May 2008

Tip: Looking for answers? Try searching our database.

Pass report's recordsource value to DAvg function call

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NZSchoolTech - 22 May 2008 00:23 GMT
I have a report that gets data from a query. In the footer of the report
I have a number of calculated fields that work with the same recordset
to display numerical calculation results. Each of these uses a DAvg
function call with specific criteria to filter out some of the data from
the recordset.

Ideally when we do calculated fields with criteria on a report it would
be nice to have the fields simply use the data that has already been fed
into the Detail section of the report. This seems so obvious that I
cannot understand why it appears that this is not provided for in
Access. In a simplified way it is provided for as a Group footer option
but without the flexibility that the domain aggregate functions give us
for criteria filtering.

If that cannot be done then I would like to know the VBA code which I
can specific in the ControlSource property of the calculated field, that
can read the Recordset property of the report and pass the value of that
property in the DAvg function call.

To make it a little more complicated but versatile I want it to
automatically know the  name of the report it is in. I tried using Me to
get this but couldn't make it work.

For example in a typical field's ControlSource property it has something
like

=DAvg("[somefield]","[somequery]","somecriteria")

Whereas ideally it would look something like

=DAvg("[somefield]",Me![RecordSource].Value, "somecriteria")

(I have tried exactly that and variations but only got errors, so it
must be wrong)
TIA
Wolfgang Kais - 22 May 2008 11:31 GMT
Hello "NZSchoolTech".

> I have a report that gets data from a query. In the footer of the
> report I have a number of calculated fields that work with the same
[quoted text clipped - 9 lines]
> option but without the flexibility that the domain aggregate
> functions give us for criteria filtering.

Right, domain aggregtate functions do not care of the environment, you
will have to use SQL aggregate functions to achieve this.

> If that cannot be done then I would like to know the VBA code which
> I can specific in the ControlSource property of the calculated field,
> that can read the Recordset property of the report and pass the value
> of that property in the DAvg function call.

You mean the [RecordSource] propety?

> To make it a little more complicated but versatile I want it to
> automatically know the  name of the report it is in. I tried using
[quoted text clipped - 9 lines]
> (I have tried exactly that and variations but only got errors, so it must
> be wrong)

"Me" can only be used in VBA, not in an expression in a calculated
field. But usually, the ojects (forms and reports) "know themselves",
so try =DAvg("[somefield]",[RecordSource],"somecriteria")

This will still cause "wrong" results, when the report is opened usig
a filter or a "where condition".

I think it's best to use SQL aggregate functions, and it should be
possible using a cinstruction like this:
=Avg(Iif(somecriteria,[somefield],Null))

Signature

Regards,
Wolfgang

NZSchoolTech - 23 May 2008 02:53 GMT
> "Me" can only be used in VBA, not in an expression in a calculated
> field. But usually, the ojects (forms and reports) "know themselves",
[quoted text clipped - 6 lines]
> possible using a cinstruction like this:
> =Avg(Iif(somecriteria,[somefield],Null))

Thanks, that has saved a lot of hair especially as the DAvg fields
stopped working when I changed my source query.
xiaojun - 30 May 2008 03:26 GMT
"NZSchoolTech" <nzschooltech@education.nz>
??????:%23K$qffHvIHA.1936@TK2MSFTNGP04.phx.gbl...

>> "Me" can only be used in VBA, not in an expression in a calculated
>> field. But usually, the ojects (forms and reports) "know themselves",
[quoted text clipped - 9 lines]
> Thanks, that has saved a lot of hair especially as the DAvg fields stopped
> working when I changed my source query.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.