VBA Excel
In a user form, the spin button brings a value up and down between 1 and 32. Value is shown in the textbox.
The user is given the possibility of typing the value directly in the textbox.
The code rejects it, if out of range, but fails to rewrite the old (good) one in the textbox to make evident that the last typed was not accepted.
I found that the typed value is processed no matter if a hit Enter or not. More to add to my confusion.
Any suggestion on how to put this straight?
I am sure I have something mixed up (properties and...?)
Gracias.
In a user form, the spin button brings a value up and down between 1 and 32. Value is shown in the textbox.
The user is given the possibility of typing the value directly in the textbox.
The code rejects it, if out of range, but fails to rewrite the old (good) one in the textbox to make evident that the last typed was not accepted.
Code:
Option Explicit
Const TTR_val_max As Byte = 32
Const TTR_val_min As Byte = 1
Private Sub TTR_control_enter()
Dim TTR_val As Byte
Dim TTR_val_old As Byte
TTR_val_old = TTR_control.Value '???
TTR_val = CByte(Val(TextBox_TTR.Text))
If TTR_val > TTR_val_max Or TTR_val < TTR_val_min Then[ATTACH=full]81803[/ATTACH]
TextBox_TTR = TTR_val_old '???
Exit Sub
Else
'Range("GC4").Value = TTR_val - for debugging only
TextBox_TTR = TTR_val
TTR_control.Value = TTR_val
End If
End Sub
Private Sub TTR_control_SpinDown()
TextBox_TTR = TTR_control.Value
End Sub
Private Sub TTR_control_SpinUp()
TextBox_TTR = TTR_control.Value
End Sub
Any suggestion on how to put this straight?
I am sure I have something mixed up (properties and...?)
Gracias.