Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with addition

Status
Not open for further replies.

weezles

Technical User
Jul 18, 2003
81
GB
Hi

I have a report with 6 columns. At the bottom of these colums I have fields which total each. I have done this in the Detail_Format section in vba using the code format:

txtTotal = ([FieldName1]+[Fieldname2]+[FieldName3])

This works perfectly fine for the first column but in subsequent columns it treats as a string (eg 1+1 = 11). I have checked everything I can think of and nothing is different with these columns to the first. I have tried deleting and starting from scratch but it still doesnt' work.

Does anyone have any ideas?

Thanks

Louise
 
Louise,

I apologize ahead if I am sending you in the wrong direction, but I believe that you can't sum fields in the detail section of the report. I believe you need to create a footer field where you can then use the Sum agregate function. If you have six columns and more then 1 row of data per column, you can differentiate one value from another. But again, I am no expert, so please take it with lots of skepticism.

David
 
Assuming your fields have integer values, to avoid them being treated as strings try:

txtTotal = (CInt([FieldName1])+CInt([Fieldname2])+CInt([FieldName3]))
 
MP9

Thanks, that worked a treat.

It doesnt' explain why one worked and others didn't, I also have 2 other reports done in the exact same way which work perfectly :-S

Louise
 
Weezles,
My guess is the values in the other text boxes are strings, for some reason. You can use the VarType function to check:
unboundtextbox = varType(FieldName1). If it returns an 8 then it is a string (2,3,4,5 integer, long, single, double). If it is not a string, but converts it and adds it like a string that would be interesting. If it is a string already, then the question would be why.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top