+ Reply to Thread
Results 1 to 6 of 6

Move cursor to textbox in a userform

Hybrid View

  1. #1
    Registered User
    Join Date
    03-22-2006
    Posts
    25

    Move cursor to textbox in a userform

    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!

  2. #2
    Martin
    Guest

    RE: 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
    >
    >


  3. #3
    Tom Ogilvy
    Guest

    RE: 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
    >
    >


  4. #4
    papou
    Guest

    Re: 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



  5. #5
    Registered User
    Join Date
    03-22-2006
    Posts
    25
    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, but how? What I made doesn't work.
    Last edited by jgmiddel; 03-29-2006 at 09:48 AM.

  6. #6
    Registered User
    Join Date
    03-22-2006
    Posts
    25
    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 Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1