+ Reply to Thread
Results 1 to 2 of 2

Having problems with textbox setfocus

  1. #1
    Terry K
    Guest

    Having problems with textbox setfocus

    Hello all,
    Below is some code that I have been working on. what I am attempting to
    accomplish was to ensure that an entry was made in this textbox and
    that the entry was numeric. If it was not I am showing a messagebox and
    attempting to reselect all the text in that same text box so that the
    user could re-enter text. The problem is that it will not go back to
    the same textbox. Instead focus continues to the next textbox.
    Am I doing something wrong? Is there another setting that I am not
    aware of?
    Any suggestions would be appreciated.


    Private Sub txttradekm_Exit(ByVal Cancel As msforms.ReturnBoolean)
    Dim txttraqdekm As TextBox
    With frmEntry
    If Not Len(txtTradekm.Text) > 0 Or Not IsNumeric(txtTradekm.Text) _
    Or Not Val(txtTradekm.Value) > 0 Then
    MsgBox "Entry must be numeric and greater than zero",
    vbInformation, "Invalid Entry"
    txtTradekm.Text = ""
    txtTradekm.SetFocus
    txtTradekm.SelStart = 0
    txtTradekm.SelLength = Len(txtTradekm.Text)
    End If
    End With
    End Sub

    Thanks Terry


  2. #2
    Edson
    Guest

    Re: Having problems with textbox setfocus

    Try this piece of code:

    Private Sub txttradekm_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Cancel = (txttradekm.Value = 0 Or (Not IsNumeric(txttradekm.Value)))
    If Cancel Then MsgBox "Entry must be numeric and greater than zero",
    vbInformation, "Invalid Entry"
    End Sub


    "Terry K" <[email protected]> escreveu na mensagem
    news:[email protected]...
    > Hello all,
    > Below is some code that I have been working on. what I am attempting to
    > accomplish was to ensure that an entry was made in this textbox and
    > that the entry was numeric. If it was not I am showing a messagebox and
    > attempting to reselect all the text in that same text box so that the
    > user could re-enter text. The problem is that it will not go back to
    > the same textbox. Instead focus continues to the next textbox.
    > Am I doing something wrong? Is there another setting that I am not
    > aware of?
    > Any suggestions would be appreciated.
    >
    >
    > Private Sub txttradekm_Exit(ByVal Cancel As msforms.ReturnBoolean)
    > Dim txttraqdekm As TextBox
    > With frmEntry
    > If Not Len(txtTradekm.Text) > 0 Or Not IsNumeric(txtTradekm.Text) _
    > Or Not Val(txtTradekm.Value) > 0 Then
    > MsgBox "Entry must be numeric and greater than zero",
    > vbInformation, "Invalid Entry"
    > txtTradekm.Text = ""
    > txtTradekm.SetFocus
    > txtTradekm.SelStart = 0
    > txtTradekm.SelLength = Len(txtTradekm.Text)
    > End If
    > End With
    > End Sub
    >
    > Thanks Terry
    >




+ 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