I have three diferent combo boxs I want to sum the second column of each combo box after update. I tried to sum the selection on a different text box, but it row them up on the text box. How can you sum the selection of the combo box on a different text box?
How can I calculate combo box selections after update?
Collapse
X
-
I'm sorry but your question is not very clear. But I'll take a whack at it anyway.
Suppose you have 3 text boxes, txtT1, txtT2, txtT3 and 3 combo boxes, cb01, cb02, cb03.
If you want to put a value from the 2nd column of each combo box in the corresponding text box, it would be like this:
If you want to add the 2nd column from all 3 combo boxes and put the value in one text box it could be like thisCode:txtT1 = cb01.Column(1) txtT2 = cb02.Column(1) txtT3 = cb03.Column(1)
The first column of a combo box is .Column(0)Code:txtT1 = cb01.Column(1) + cb02.Column(1) + cb03.Column(1)
Hope this helps.
Jim -
You've posted this same question 3 times already, so I've deleted the other two.
If you want the question answered clearly then you will need to give more than 30 seconds to formulating the question. It needs a clear explanation. Without one we can only guess at what you really mean, which is a bit of a waste of time.
Please read FAQ: Posting Guidelines carefully before posting again.Comment
-
bdominiq, If you look at the second bit of code I posted, you will see that it is doing exactly what you want. It is totaling a column from 3 combo boxes and putting the total into one text box. I have named my text box txtT1, and the combo boxes are cb01, cb02, and cb03.
JimComment
-
for some odd reason when I use the following formula,I'm sorry but your question is not very clear. But I'll take a whack at it anyway.
Suppose you have 3 text boxes, txtT1, txtT2, txtT3 and 3 combo boxes, cb01, cb02, cb03.
If you want to put a value from the 2nd column of each combo box in the corresponding text box, it would be like this:
If you want to add the 2nd column from all 3 combo boxes and put the value in one text box it could be like thisCode:txtT1 = cb01.Column(1) txtT2 = cb02.Column(1) txtT3 = cb03.Column(1)
The first column of a combo box is .Column(0)Code:txtT1 = cb01.Column(1) + cb02.Column(1) + cb03.Column(1)
Hope this helps.
Jim
instead of getting the total it just place the value of the combo box in one row, like this 601510000. 60 is the price of the first combo 15 is the second one, and 100 is third and finaly the two zeros are the last tow combo s values. Any idea why it's doing that?Code:=[Combo100].[column](1)+[Combo102].[column](1)+[Combo104].[column](1)+[Combo106].[column](1)+[Combo108].[column](1)
Comment
-
From your post it's hard to tell whether you're completely ignoring the suggestion or you simply don't understand. What you say is so unclear.
Jim's code is in VBA and is a valid assignment. If you are using what you posted as a formula in a field in your query or in a control on your form then I wouldn't expect it to work at all. You say it returns a value, which appears to be what you requested in the first place, if so then why is that not right for you?
I suggested before that you take more care with your posts. It doesn't appear that you have taken that on board. I can only say that such a careless approach is unlikely to get your question answered in a way you seem to need.Comment
-
It looks like [Combo100].[column](n) returns string value, it should be converted to number via Val() function.for some odd reason when I use the following formula,
instead of getting the total it just place the value of the combo box in one row, like this 601510000. 60 is the price of the first combo 15 is the second one, and 100 is third and finaly the two zeros are the last tow combo s values. Any idea why it's doing that?Code:=[Combo100].[column](1)+[Combo102].[column](1)+[Combo104].[column](1)+[Combo106].[column](1)+[Combo108].[column](1)
Regards,
FishComment
-
Yes, it looks like you are getting concatenation of strings. I haven't used Val(), I have to look at that. I would have said
=Cdbl([Combo100].[column](1))+Cdbl([Combo102].[column](1))+cdbl([Combo104].[column](1))+Cdbl([Combo106].[column](1))+Cdbl([Combo108].[column](1))
or use Cint or Clng, depending on the values possible.
I would have expected your code to work. I wonder if this is caused by the formatting you have applied to the combo box objects?
I'm going to go look at Val(). I really appreciate learning more about VB/VBA from others here.
JimComment
-
You are right Jim.Yes, it looks like you are getting concatenation of strings. I haven't used Val(), I have to look at that. I would have said
=Cdbl([Combo100].[column](1))+Cdbl([Combo102].[column](1))+cdbl([Combo104].[column](1))+Cdbl([Combo106].[column](1))+Cdbl([Combo108].[column](1))
or use Cint or Clng, depending on the values possible.
I would have expected your code to work. I wonder if this is caused by the formatting you have applied to the combo box objects?
I'm going to go look at Val(). I really appreciate learning more about VB/VBA from others here.
Jim
CDbl, Clng, CInt and the similar functions could be more suitable since they return value of a required type, while Val() returns Double.
By the way, string could be converted to double using the following operations:
"1234" * 1 - returns Double 1234
"1234" + 0 - returns Double 1234
and number could be converted to string using the following operation:
1234 & "" - returns String "1234"Comment
Comment