Link to home
Start Free TrialLog in
Avatar of Sara Hedtler
Sara Hedtler

asked on

Calculating Sales Tax

I've tried to create a Form to Calculate Sales and Taxes, but I'm not able to get the form to work.  Super new to vba, off and on for a few years and its now become imperative for me to get this done.  This is the code i have so far.

Private Sub txtSalesTax_Change()

Me.txtSubtotal.Text = Val(Replace(txtSalesPrice.Text, "$", "")) * Val(Replace(txtSalesTax.Text, "%", "")) / 100

End Sub

Private Sub txtSubtotal_AfterUpdate()

Me.txtSubtotal.Value = Format(txtSubtotal.Text, "$0,00")

End Sub

Private Sub txtSalesTax_AfterUpdate()

Me.txtSalesTax.Text = Val(txtSalesTax.Value) / 100
Me.txtSalesTax.Text = Format(txtSalesTax, "Percent")

End Sub


Private Sub txtTotalSale_Values()
    Dim dbltxtTotalSale As Double

    On Error Resume Next

    dbltxtTotalSale = CDbl(txtSubtotal.Value)
    dbltxtTotalSale = dbltxtSubtotal + CDbl(PriceIncrease.Value) - CDbl(txtSubtotal.Value)
    dbltxtTotalSale = dbltxtTotalSale + CDbl(PriceIncrease.Value)

    txtTotalSale.Value = dbltxtTotalSale
   
    txtTotalSale = Format(txtTotalSale, "$0.00")

End Sub
Avatar of Tusitala
Tusitala

Hi,

Could you please outline your process a little more?

For example, which text boxes are you allowing users to enter data into? Which ones are locked? Do you have any other controls on the form? Is your form bound to a table or recordset?

-Tala-
Avatar of Ryan Chong
the line below looks weird...

Me.txtSalesTax.Text = Val(txtSalesTax.Value) / 100

Open in new window


if the SalesTax is based on Subtotal, you can update the SalesTax in  txtSubtotal_AfterUpdate() event.

like:
Private Sub txtSubtotal_AfterUpdate()

Me.txtSubtotal.Value = Format(txtSubtotal.Text, "$0,00")

Me.txtSalesTax.Text = Format(txtSalesTax, "Percent")

End Sub

Private Sub txtSalesTax_AfterUpdate()

End Sub

Open in new window

Avatar of Sara Hedtler

ASKER

Thank you!  I've attached the workbook to see.
I thought i had attached it, but apparently not.
sales---tax.xlsm
can you advise what is not working here?

User generated image
It wasn't working for me. Not sure if I was using the right code.
yea, it may not worked at this moment, but can you tell us the logic of calculations so we can build the right codes
I think i almost have it, its just the totals not working. sales---tax--revised-5-5-17.xlsm
can you tell us the logic behind the calculation of Total Sale?

we can't just guess what you needed.
I need the total to calculate from Subtotal, Sales Price and Price Increase to sum.
if you have:

Price Increase : $20.00
Sales Price: $100.00
Sales Tax: 3.00%
Sub Total: $3.60

what is the expected Total Sale?
$123.60
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial