Reputation: 423
I have a table called TestTable with 3 fields called A,B and C
I'm trying to display on an Access 2003 report form the total number of records returned via a query in one textbox - Control Source set to "=Count(*)",
and that works ok, and in another textbox display this value as a percentage of the total numbers of records, something like,
(Count(*)/total) * 100
But I'm having problems displaying the correct value in the second (percentage) textbox. I've tried setting a global variable to this value through the use of DCount("*", "TestTable")
as part of an OpenRecordset Sub. This method works in the main user form however I can't seem to use such variables in a control source for this record.
Is there an easy way to do this?
Upvotes: 0
Views: 1001
Reputation: 2302
You can use DCount("*", "TestTable")
directly!
Why set a global variable?!
In the percentage textbox ControlSource
property should be:
=(Count(*)/DCount("*", "TestTable")) * 100
BTW: If you set the Format
property to Percent
you can miss out the * 100
FYI: In order to access global variables from a ControlSource
property you must use a function that returns the value of the global. Globals themselves are not accessible.
Upvotes: 1