+ Reply to Thread
Results 1 to 4 of 4

Goto Specific Textbox in Userform

  1. #1
    Kris_Wright_77
    Guest

    Goto Specific Textbox in Userform

    I am developing userform that needs to validate any change in a textbox.
    If the new data is outside of the specified region, then I want the current
    textbox to be remain selected, but unfortunately I cant find a way to do this.

    The code I am currently using is

    Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    BENCH_Tour_Amber_txt.Value = Format(Me.BENCH_Tour_Amber_txt.Value, "")
    Else
    MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    Buttons:=vbExclamation

    End If
    End Sub

    Also
    This re-occurs numerous times in the same userform, so is it possible to
    write the code no matter which textbox is "exited", or will I just have to
    repeat for each textbox??

    Thanks for any help that you can give.

  2. #2
    Tom Ogilvy
    Guest

    Re: Goto Specific Textbox in Userform

    Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    BENCH_Tour_Amber_txt.Value = Format(Me.BENCH_Tour_Amber_txt.Value,
    "")
    Else
    MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    Buttons:=vbExclamation
    Cancel = True
    End If
    End Sub

    For the exit event, since it is provided by the controls container, you
    would need to create one for each textbox.

    --
    Regards,
    Tom Ogilvy


    "Kris_Wright_77" <[email protected]> wrote in message
    news:[email protected]...
    > I am developing userform that needs to validate any change in a textbox.
    > If the new data is outside of the specified region, then I want the

    current
    > textbox to be remain selected, but unfortunately I cant find a way to do

    this.
    >
    > The code I am currently using is
    >
    > Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As

    MSForms.ReturnBoolean)
    > If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    > BENCH_Tour_Amber_txt.Value = Format(Me.BENCH_Tour_Amber_txt.Value,

    "")
    > Else
    > MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    > Buttons:=vbExclamation
    >
    > End If
    > End Sub
    >
    > Also
    > This re-occurs numerous times in the same userform, so is it possible to
    > write the code no matter which textbox is "exited", or will I just have to
    > repeat for each textbox??
    >
    > Thanks for any help that you can give.




  3. #3
    Kris_Wright_77
    Guest

    Re: Goto Specific Textbox in Userform

    Thanks
    Works exactly the way I wanted.

    Could you let me know why this works?
    I have seen it used similarly in other pieces of code that I have found and
    adapted from this forum, and obviously didn't need to understand
    My VBA is entirely self taught, and haven't been able to find any
    explanations in the couple of reference books that I have.

    Kris

    "Tom Ogilvy" wrote:

    > Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    > If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    > BENCH_Tour_Amber_txt.Value = Format(Me.BENCH_Tour_Amber_txt.Value,
    > "")
    > Else
    > MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    > Buttons:=vbExclamation
    > Cancel = True
    > End If
    > End Sub
    >
    > For the exit event, since it is provided by the controls container, you
    > would need to create one for each textbox.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Kris_Wright_77" <[email protected]> wrote in message
    > news:[email protected]...
    > > I am developing userform that needs to validate any change in a textbox.
    > > If the new data is outside of the specified region, then I want the

    > current
    > > textbox to be remain selected, but unfortunately I cant find a way to do

    > this.
    > >
    > > The code I am currently using is
    > >
    > > Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As

    > MSForms.ReturnBoolean)
    > > If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    > > BENCH_Tour_Amber_txt.Value = Format(Me.BENCH_Tour_Amber_txt.Value,

    > "")
    > > Else
    > > MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    > > Buttons:=vbExclamation
    > >
    > > End If
    > > End Sub
    > >
    > > Also
    > > This re-occurs numerous times in the same userform, so is it possible to
    > > write the code no matter which textbox is "exited", or will I just have to
    > > repeat for each textbox??
    > >
    > > Thanks for any help that you can give.

    >
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: Goto Specific Textbox in Userform

    Cancel is a variable defined by the event declaration. If is found in the
    argument list of most events that start with BEFORE and it used to signal
    the triggering activity not to occur. While exit is not entitled
    BeforeExit, setting cancel to true still causes the Exit action not to
    occur.

    --
    Regards,
    Tom Ogilvy


    "Kris_Wright_77" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks
    > Works exactly the way I wanted.
    >
    > Could you let me know why this works?
    > I have seen it used similarly in other pieces of code that I have found

    and
    > adapted from this forum, and obviously didn't need to understand
    > My VBA is entirely self taught, and haven't been able to find any
    > explanations in the couple of reference books that I have.
    >
    > Kris
    >
    > "Tom Ogilvy" wrote:
    >
    > > Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As

    MSForms.ReturnBoolean)
    > > If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    > > BENCH_Tour_Amber_txt.Value =

    Format(Me.BENCH_Tour_Amber_txt.Value,
    > > "")
    > > Else
    > > MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    > > Buttons:=vbExclamation
    > > Cancel = True
    > > End If
    > > End Sub
    > >
    > > For the exit event, since it is provided by the controls container, you
    > > would need to create one for each textbox.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Kris_Wright_77" <[email protected]> wrote in

    message
    > > news:[email protected]...
    > > > I am developing userform that needs to validate any change in a

    textbox.
    > > > If the new data is outside of the specified region, then I want the

    > > current
    > > > textbox to be remain selected, but unfortunately I cant find a way to

    do
    > > this.
    > > >
    > > > The code I am currently using is
    > > >
    > > > Private Sub BENCH_Tour_Amber_txt_Exit(ByVal Cancel As

    > > MSForms.ReturnBoolean)
    > > > If Not BENCH_Tour_Amber_txt.Value <> 100 Then
    > > > BENCH_Tour_Amber_txt.Value =

    Format(Me.BENCH_Tour_Amber_txt.Value,
    > > "")
    > > > Else
    > > > MsgBox Prompt:="Amber Tolerance Must Be Between 0 & 100",
    > > > Buttons:=vbExclamation
    > > >
    > > > End If
    > > > End Sub
    > > >
    > > > Also
    > > > This re-occurs numerous times in the same userform, so is it possible

    to
    > > > write the code no matter which textbox is "exited", or will I just

    have to
    > > > repeat for each textbox??
    > > >
    > > > Thanks for any help that you can give.

    > >
    > >
    > >




+ 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