ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Move cursor to textbox in a userform (https://www.excelbanter.com/excel-programming/357438-move-cursor-textbox-userform.html)

jgmiddel[_4_]

Move cursor to textbox in a userform
 

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

--
jgmidde
-----------------------------------------------------------------------
jgmiddel's Profile: http://www.excelforum.com/member.php...fo&userid=3271
View this thread: http://www.excelforum.com/showthread.php?threadid=52754


Martin

Move cursor to textbox in a userform
 
TextBox1.SetFocus

"jgmiddel" wrote:


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

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

The error is given in a MsgBox.

Thanks in advance!


--
jgmiddel
------------------------------------------------------------------------
jgmiddel's Profile: http://www.excelforum.com/member.php...o&userid=32714
View this thread: http://www.excelforum.com/showthread...hreadid=527545



Tom Ogilvy

Move cursor to textbox in a userform
 
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.

--
Regards,
Tom Ogilvy


"jgmiddel" wrote:


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

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

The error is given in a MsgBox.

Thanks in advance!


--
jgmiddel
------------------------------------------------------------------------
jgmiddel's Profile: http://www.excelforum.com/member.php...o&userid=32714
View this thread: http://www.excelforum.com/showthread...hreadid=527545



Papou

Move cursor to textbox in a userform
 
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



jgmiddel[_5_]

Move cursor to textbox in a userform
 

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

--
jgmidde
-----------------------------------------------------------------------
jgmiddel's Profile: http://www.excelforum.com/member.php...fo&userid=3271
View this thread: http://www.excelforum.com/showthread.php?threadid=52754


jgmiddel[_6_]

Move cursor to textbox in a userform
 

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

--
jgmidde
-----------------------------------------------------------------------
jgmiddel's Profile: http://www.excelforum.com/member.php...fo&userid=3271
View this thread: http://www.excelforum.com/showthread.php?threadid=52754



All times are GMT +1. The time now is 06:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com