Move cursor to textbox in a userform

  • Thread starter Thread starter jgmiddel
  • Start date Start date
J

jgmiddel

Hi, I would like to check (on Exit) a value entered in a textbox with

certain cell. That's not the problem, but I would like to find a metho
how
to move the cursor to the wrong entered value (so: back to tha
textbox).

The error is given in a MsgBox.

Thanks in advance
 
Better to use the Exit Event of the Textbox to check the entry. Then if it
is improper, the Event has a Cancel variable. If you set this to False, the
textbox won't be exited. It sounds like you are probably already using
this event to popup a msgbox, so just set the Cancel variable to true.
 
Hello
In addition, you could highlight the whole (wrong)entry with:
With Me.TextBox1
..SelStart = 0
..SelLength = Len(.Value)
..SetFocus
End With

HTH
Cordially
Pascal
 
Tom,

The data must be proceeded in a worksheet, so I use this:

Private Sub naam1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Range("Werkblad!A12") < 3 Then
Dim Msg, Style, Title, Response
Msg = Range("error1").Value
Style = vbInformation
Title = Range("naam").Value
Response = MsgBox(Msg, Style, Title)
On Error Resume Next
Userform.naam1.SetFocus
End If
End Sub

You say, the exit can be canceled. What I made doesn't work
 
Done!
Private Sub naam1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Range("Werkblad!A12") < 3 Then
Dim Msg, Style, Title, Response
Msg = Range("error1").Value
Style = vbInformation
Title = Range("naam").Value
Response = MsgBox(Msg, Style, Title)
On Error Resume Next
Cancel = True
End If
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top