VBA Code to Sum field values

papadega3000

Registered User.
Local time
Today, 08:01
Joined
Jun 21, 2007
Messages
80
I have a table that has two fields which I want to sum the one field based on the other field. The field I want to sum is a number data type and the other is a text data type. My research has pointed me in the direction of using this line of code.

totalP = DSum("[FieldX]", "TableName", "[CriteriaField] = HAVING ?")

My issue is in the criteria area. I will have a number of records that have matching CriteriaField text and I want to add them up. The issue is what syntax do I use to say that I want to Sum all records that contain the same criteriaField. The text field is in this format 1.1.1.

Is there a special function that lets me match text?

Thanks,
 
If VBA help is anything to go by then isn't it
totalP = DSum("[FieldX]", "TableName", "[CriteriaField] = '1.1.1'")

or am missing something?

Brian
 
Having thought about it I think what you're after is the equivalent of a Totals query grouping on the Criteria field and summing Fieldx, do you have to use VBA?

Brian
 
That is what I am looking for. I don't have to use VBA I was just going that way. If I can get away with just making a query I will.
In that case do I just set a query to total the FieldX and make the Criteria Box set to CriteriaField?


In response to your first reply...Its not just that easy because the critieria is different because the criteria is based off another table.
 
I got it working as a query by making a sum query and eliminating a query on the individual items that make up the criteria field and it gave me the totals I was looking for.

Thanks for your help... I have been working on this project for a while and I am simply just overlooking/overanalyzing the tasks.
 

Users who are viewing this thread

Back
Top Bottom