Querry

JRPMD

Registered User.
Local time
Today, 04:41
Joined
Nov 24, 2012
Messages
52
Hello, I have a querry with this calculated field :

Expr1: DCont("[hta]","Pacientes antecedentes totales","[HTA]='1' ")/DCont("[HTA]","Pacientes antecedentes totales")*100

It is a percentage of value 1 over the total registers with a value for HTA.

If I apply a criteria in a diferent field (i.e age , gender) the results remains over all the registers with a value in field HTA , instead of a limited number of registers by other criteria .
So I can't see this results for any kind of limited registers in the same querry.
Can you help me ?
Thank you very much!
 
Code:
DCont("[hta]","Pacientes antecedentes totales","[HTA]='1' ")

See the [HTA]='1' portion in your code? That is the criteria of the DCont. That's the only criteria the Dcont is using. So any other criteria you use in your criteria of the Query will not be used by the Dcont, you must add it to the 3rd argument of the Dcont for it to be used by the Dcont.

However, you shouldn't use Dcont in a query. Instead, my suggestion is to use a sub-query to do the totaling there. That query would be a totals query (https://support.office.com/en-za/ar...-a-query-430a669b-e7fd-4c4b-b154-8c8dbbe41c8a) and use the COUNT function of SQL, not the Dcont function of VBA.

Then in that sub-query you can apply all the criteria you want and it will be used in calculating your totals.
 
Thank you very much for your answer . I will try it.
 

Users who are viewing this thread

Back
Top Bottom