PDA

View Full Version : Show sum of textboxes in a textbox.



novicetech1
09-14-2012, 01:30 PM
Hi All -

First time here as a member, though I've learned lots from the site just browsing. Anyway, I have a userform that tracks travel expenses. I have a textbox for mileage, one for mileage rate paid, one for lodging and one for meals. At the moment I have the calculation in a command button called "Add New Record". When the button is clicked, the calculation is executed and the value appears in the "Totals" textbox (txtTotCost).

My question is: is there a way to make the value appear in the "Totals" textbox before the user hits submit? I have built in a way to edit or delete records after they have been submitted, but it just seems like the right approach to display all of the data prior to submitting.

At present, I do not have any code in the txtTotCost textbox. Here is the code I have in the "Submit" button:



txtTotCost.Value = "$" & (Val(Me.txtMileage.Text) * Val(Me.txtRate.Text)) +
Val(Me.txtLodging.Value) + Val(Me.txtMeals.Value)


I appreciate any help you can offer. Thanks.

Simon Lloyd
09-14-2012, 01:45 PM
You'd have to put the code for summing the textboxes in each textboxes -change event so as the textbox is changed the total box is updated.

novicetech1
09-14-2012, 03:40 PM
Hi Lloyd. Thanks for the help. Also, I read the article you suggested. I'm pretty new to vba and the forums so I didn't realize that I was cross-posting even with a different issue. I rather thought I was casting my net further afield. But I fully understand and will respect the concern. Thanks for letting me know. I truly did not know I was doing something wrong. I appreciate the heads up.

Simon Lloyd
09-14-2012, 04:23 PM
I think you've misread things, that link is ALWAYS in my signature, crossposting is when you post in more than one forum with the same question, so you've done nothing wrong :)

Did you manage to resolve your query?