Set focus don't work

  • Thread starter Thread starter garnote
  • Start date Start date
G

garnote

Hi all,

Private Sub TextBox1_AfterUpdate()
If Len(TextBox1.Text) > 5 Then
MsgBox "Invalide"
With TextBox1
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub

Why Textbox1 don't have the focus with this Sub ?

Thanks,

Serge
 
Serge,

Use the Exit event

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1.Text) > 5 Then
MsgBox "Invalide"
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
Cancel = True
End With
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
OK but when a textbox have the focus,
cursor is in the textbox or text of the textbox
is selected. Here, how is possible select the text
with this Sub ?

Serge
 
Serge,

Not sure I understand, but on an error the text is already selected, and any
typing removes it all unless the arrow keys or mouse is used to select a
particular part.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top