A
Alan
I have a bunch of ActiveX Text Boxes set up on a User Form. One,
for which I should code below, is called "NumberOfWeeks". It has an
option button, "EveryXweeksOption", associated with it. I set up the
_BeforeUpdate method to change the option selection to this option
when a user enters a value in the text box when the option is not
selected.
The problem is that, when a user enters valid text (a number)
when the option is not selected, the option selection changes
correctly but the focus changes to another text box. I want to keep
the focus on the text box associated with the selected option.
Any ideas on how I can achieve this? I have searched but
cannot find this information. I am new to VBA user interfaces.
Thanks, Alan
Private Sub NumberOfWeeks_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)
ErrorLabel.Visible = False
If EveryXweeksOption.Value = False Then
EveryXweeksOption.Value = True
End If
With NumberOfWeeks
Dim InString As String
InString = .Text
If Not (IsNumeric(InString)) Or (Len(InString) > 3) Then
DisplayErrorLabel ("You must enter a 1-3 digit number
here")
Cancel = True
.SelStart = 0
.SelLength = 100
.SetFocus
.Text = "1"
End If
End With
End Sub
for which I should code below, is called "NumberOfWeeks". It has an
option button, "EveryXweeksOption", associated with it. I set up the
_BeforeUpdate method to change the option selection to this option
when a user enters a value in the text box when the option is not
selected.
The problem is that, when a user enters valid text (a number)
when the option is not selected, the option selection changes
correctly but the focus changes to another text box. I want to keep
the focus on the text box associated with the selected option.
Any ideas on how I can achieve this? I have searched but
cannot find this information. I am new to VBA user interfaces.
Thanks, Alan
Private Sub NumberOfWeeks_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)
ErrorLabel.Visible = False
If EveryXweeksOption.Value = False Then
EveryXweeksOption.Value = True
End If
With NumberOfWeeks
Dim InString As String
InString = .Text
If Not (IsNumeric(InString)) Or (Len(InString) > 3) Then
DisplayErrorLabel ("You must enter a 1-3 digit number
here")
Cancel = True
.SelStart = 0
.SelLength = 100
.SetFocus
.Text = "1"
End If
End With
End Sub