PDA

View Full Version : Spinbutton value



av8tordude
08-26-2012, 11:18 AM
I have this code to count up, if there is no value (which works fine)

TextBox2 = SpinButton2.Value

If I click the up arrow, to add to the existing value, it starts counting from 1, instead of the next higher value (i.e. 3...4...5 etc). In an attempt to resolve the issue, I used TextBox2 = TextBox2 + SpinButton2.Value, which works, but only if there is a value in the textbox. If there is no value, it errors.

Also, If I click the down arrow, it does not count down. It simply does not do anything. If there is a value, I like to be able to count down, but once reaching 0, it should go blank.

Can someone assist. Thanks you kindly

TextBox2 = TextBox2 + SpinButton2.Value

mikerickson
08-26-2012, 11:46 AM
PerhapsTextBox2.Text = Val(TextBox2.Text) + SpinButton2.Value

av8tordude
08-26-2012, 12:19 PM
I fix the the counting down part by adding the .text, but I still have the problem where is starts counting from 1 if there is an existing value. Instead of counting from (i.e. 3...4...5 etc.) , in the existing value is 2, it would start from 1...2...3 etc

p45cal
08-26-2012, 01:04 PM
Can you confirm these are activeX controls.
And are they on a Userform or on a sheet?

snb
08-27-2012, 03:34 PM
TextBox2.Text = SpinButton2.Value + TextBox2.Text

mikerickson
08-27-2012, 10:00 PM
Private Sub SpinButton2_Change()
TextBox2.Text = SpinButton2.Value
End Sub

Private Sub TextBox2_AfterUpdate()
Dim txtVal As Long
txtVal = Abs(CLng(Val(TextBox2.Text)))
With SpinButton2
.Max = Application.Max(2 * txtVal, .Max)
.Min = Application.Min(txtVal \ 2, .Min)
.Value = txtVal
End With
End Sub