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
SalesVBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
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-
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

Sara Hedtler

ASKER
Thank you!  I've attached the workbook to see.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Sara Hedtler

ASKER
I thought i had attached it, but apparently not.
sales---tax.xlsm
Ryan Chong

can you advise what is not working here?

SnapShot.png
Sara Hedtler

ASKER
It wasn't working for me. Not sure if I was using the right code.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

yea, it may not worked at this moment, but can you tell us the logic of calculations so we can build the right codes
Sara Hedtler

ASKER
I think i almost have it, its just the totals not working. sales---tax--revised-5-5-17.xlsm
Ryan Chong

can you tell us the logic behind the calculation of Total Sale?

we can't just guess what you needed.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Sara Hedtler

ASKER
I need the total to calculate from Subtotal, Sales Price and Price Increase to sum.
Ryan Chong

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?
Sara Hedtler

ASKER
$123.60
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.