I have about 10 txtboxes in a UserForm. I have a LblTotal that I would like to have updated everytime there is a change in those txtboxes. How can I do that?
I have about 10 txtboxes in a UserForm. I have a LblTotal that I would like to have updated everytime there is a change in those txtboxes. How can I do that?
What do you want totalled and where if you want LblTotal to be the combined total of the textboxes maybe Me.LblTotal=textbox1.value + Textbox2.value....etc
or do you want to count the amount of controls?
Me.Controls.Count?
Regards,
Simon
Regards,
Simon
Please read this before cross posting!
In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
If I have seen further it is by standing on the shoulders of giants.
Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)
Well the txtboxes would just be a number. So I am trying
Me.LblTotal.Caption = TxtQua1.Value + TxtQua2.Value + TxtQua3.Value + TxtQua4.Value + TxtQua5.Value + TxtQua6.Value + TxtQua7.Value + TxtQua8.Value + TxtQua9.Value + TxtQua10.Value + TxtQua11.Value + TxtQua12.Value
But that's not working its not giving me anything.
Where should I put that?
Not sure Em but I think you have to dim the textbox variables as integers...this works but I only did the first 2 textboxes for you....
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
That adds them but I would like for that to happen automatically not have to click a cmd button. Can that be done?
Use the textbox exit procedure.
Would I need that in each textbox?
Yep.
Instead of it giving me a sum it's giving me 1111
If the first 4 are 1's.
How can I assign txtboxes to be integers?
Add them, don't concatenate.
please explain
Use CDbl(Texbox1.Text) + CDbl(TextBox2.Text) + ...
instead of
TextBox1.Text + TextBox2.text + ...
The Textbox1 + Textbox2....is my fault Bob, i forgot about one of your answers to earlier posts where you Cast Double.
Apologies!
Regards,
Simon
Please read this before cross posting!
In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
If I have seen further it is by standing on the shoulders of giants.
Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)
You would think that it would be smart enough to know that + means add, and automatically Cast it for you. After all, there is a & operator to allow true concatenation.
Well when i wrote "+" that was my assumption because with what little i know, i know that "&" means this AND that. All i can imagine Bob is that it must have been a human that devised the language and had he or she made it perfect there would be no room for improvement and no Excel 2007 etc!
LOL!
Regards,
Simon
Please read this before cross posting!
In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
If I have seen further it is by standing on the shoulders of giants.
Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)
and then where would MS be ?
I would imagine Bill Gates would still be drawing on his UB40!
Regards,
Simon
Please read this before cross posting!
In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
If I have seen further it is by standing on the shoulders of giants.
Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)
How can I have that work without having to click anything. I have cmdbuttons that will autopopulate some of the TxtQua Boxes.
Hi Em,
I would add a sub to the userform like this:
[vba]Private Sub add()
LblTotal.Caption = CDbl(TxtQua1.Text) + CDbl(TxtQua2.Text) _
+ CDbl(TxtQua3.Text) + CDbl(TxtQua4.Text) + CDbl(TxtQua5.Text)
End Sub
[/vba]
then in each command button add a call to the add routine like this:
[vba]Private Sub CmdNC8430_Click()
LoadTextBoxes "HP NC8430", "", "1"
LoadTextBoxes "LAPTOP BAG", "Expense", "1"
LoadTextBoxes "KEYBOARD", "Expense", "1"
LoadTextBoxes "MOUSE", "Expense", "1"
LoadTextBoxes "PORT REPLICATOR", "Expense", "1"
add
End Sub[/vba]
I only did the one button for you but you can get it from there I'm sure
CmdNC8430_Click() is the one I set up for you in the attachment. You will have to add the call to "add" to each commandbutton
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Hey lucas that seems to work good only thing is it's giving me an error. It seems the reason it's giving me an error is because the other values are "". How can I fix that.
I have this
Private Sub add()
UserForm1.LblTotal.Caption = CDbl(TxtQua1.Text) + CDbl(TxtQua2.Text) + CDbl(TxtQua3.Text) + CDbl(TxtQua4.Text) + CDbl(TxtQua5.Text) + CDbl(TxtQua6.Text) '+ CDbl(TxtQua7.Text) + CDbl(TxtQua8.Text) + CDbl(TxtQua9.Text) + CDbl(TxtQua10.Text) + CDbl(TxtQua11.Text) + CDbl(TxtQua12.Text)
End Sub
So if a cmdbutton is only 4 or 5 lines TxtQua6.Text through TxtQua12.Text = "". Any way i can possibly do an if statement to test if it's "" if so then ignore