Home > Software design >  How to Sum FormatCurrency() Value?
How to Sum FormatCurrency() Value?

Time:10-13

SAMPLE: I have sales in two days and I formatted each value per day in Currency

Dim firstSales,secondSales as String

firstSales = 1500
secondSales = 1500

Me.firstDaySales.Caption = FormatCurrency(firstSales)
Me.secondDaySales.Caption = FormatCurrency(secondSales)

I got the right format for each value per day in caption

Me.totalSales.Caption = Val(firstDaySales)   Val(secondDaySales)

But when I try to get the total Sum of Val(firstDaySales) and Val(secondDaySales) I got the wrong answer "0" beacause the value of Val(firstDaySales) and Val(secondDaySales) become "?1,500.00", it didn't recognize as a number or currency. How to solve it?

Thank You.

CodePudding user response:

Add the values, not the captions, then format


Dim firstSales As Double 
Dim secondSales as Double 

firstSales = 1500
secondSales = 1500

Me.firstDaySales.Caption = FormatCurrency(firstSales)
Me.secondDaySales.Caption = FormatCurrency(secondSales)

Me.TotalSales.Caption = FormatCurrency(firstSales   secondSales)
  • Related