By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

the sum of two combo boxes in another text box

P: 1
I have two combo boxes, freight and Rigging both have drop down selections from a table. I have a third text box i want the sum of these two boxes in. I can't seem to get it to add right.
Feb 22 '17 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,430
In which columns are the prices held?

Feb 23 '17 #2

P: 1
Not a lot of data to go on so I will assume what you are trying to do is something along the lines of obtaining a total cost.

I would handle it something like this:

Expand|Select|Wrap|Line Numbers
  1. txtTotalCost.Value = CDbl(Freight.Value) + CDbl(Rigging.Value)
Without using CDbl(), if the values in freight and/or rigging are strings the result will be a concatenation of the two values which isn't what you would want based on my initial assumption.

(e.g. "10000" + "100" = "10000100")

CDbl() converts whatever datatype the value is in the box to a numeric value (provided the value is identifiably numeric and not something like "RED" which will throw an error) so the result is an addition of the values rather than a combining.

(e.g. CDbl("10000") + CDbl("100") = 10100)

To get the textbox to have an initial value as you load the form and move through the records, put the code in the Form's On Current event. To update the value if the numbers change in the comboboxes put the same code in the After Update event of the comboboxes.

Or... better yet, create a function to do it and just call the function from the Current and After Update events. That way you aren't redundantly repeating code, and if you ever have to update the formula you can update it in just one place and not have to find every instance of it.
Mar 2 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.