I have a series of textboxes, and validation on each one. If the textbox value passes validation, I want to make the next textbox visible, and set the focus to it. If it doesn't, I want to remain on the current textbox. However, I cannot make a textbox visible and then set the focus to it. Here is an example attempt:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If (IsNumeric(TextBox2.Value)) Then
TextBox3.Visible = True
'BoxForm.Repaint
TextBox3.SetFocus
Else
StatusLabel.Caption = "Box 2: not a number"
Cancel = True
End if
end sub
I have tried putting the setfocus statement in several different event handlers, but it doesn't help. Nor does the form repaint. If TextBox3 was already visible, it would work fine. How do I do this?
edit: I tried using FainDuru's advice (thanks!) to disable and re-enable TextBox3, (in _BeforeUpdate, then in _afterUpdate), but neither seemed to have any effect. _Repaint doesn't help either. The focus wants to go to the next widget which was visible before the event sequence. I even tried refocusing back from the next widget's _Enter event, but that does nothing. It is as though TextBox3 isn't activated until after the event cascade ends. If TextBox3 starts out visible, everything works correctly. Any other ideas?