PDA

View Full Version : Using SUM with VBA



Mattster2020
08-11-2009, 03:43 AM
Morning All,

I having difficulty adding two values together, im using the below code:

Mon3 = (Mon1 + Mon2)

I get the following result:

120400

These are the two values im trying to add i.e 120 + 400.

How can I sum these two values together, and not actually put the two values side by side?

Regards,

Matt

OBP
08-11-2009, 03:59 AM
Access is treating them as Text strings, have you made sure that they are actually Values (Numbers) in the Table fields?

CreganTur
08-11-2009, 05:12 AM
If you have to save your data as a string type for some strange reason, you can use something called Type Casting to change the data type of a value on the fly in your code- the change is temporary- it doesn't change the actual value of the variable.

This example casts the variables as Integer data type.

Mon3 = CInt(Mon1) + CInt(Mon2)

HTH:thumb