Results 1 to 7 of 7

Thread: getting the last textbox that was focussed on and placing the focus on it

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Resolved getting the last textbox that was focussed on and placing the focus on it

    Hello

    Is it possible to get the last textbox that was focussed on set the focus back on it.

    what i mean is say i had footext1.text and then moved to footext2.
    and then due to an error condition, i want to go back to footext1,

    is it possible to get the last "focussed textbox" and then select that textbox again?
    Last edited by vb_student; Sep 22nd, 2005 at 05:07 PM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: getting the last textbox that was focussed on and placing the focus on it

    do your errorcheck in the Validate event of the checkbox...
    Setting cancel to true will stop it from going to the next checkbox
    like this:
    VB Code:
    1. Private Sub footext1_Validate(Cancel As Boolean)
    2.     If CheckForErrorIsError Then
    3.         Cancel = True
    4.         footext1.SelStart = 0
    5.         footext1.SelLength = Len(footext1)
    6.     End If
    7. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: getting the last textbox that was focussed on and placing the focus on it

    thanks for the reply

    is the validate method used when the textbox is about to go out of focus?

    i guess the footext1.length repastes the text previously in the textbox, correct?

    i guess the checkforerror is a flag, and i should probably name itas footextcheckforerror and initialise it to True in the form_load method, correct?

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: getting the last textbox that was focussed on and placing the focus on it

    no
    ok..

    the the selstart & sellength are to make it Highlight the text in the textbox so when the user types it will replace whats there...

    the checkforerror was just made up.. you need to put your code in to check for the error. (not sure what you are checking for)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: getting the last textbox that was focussed on and placing the focus on it

    thanks for the reply [A51g]Static
    is the answer no, for both my questions
    1. is the validate method used when the textbox is about to go out of focus?

    2. i guess the footext1.length repastes the text previously in the textbox, correct?

    can you tell me when the validate method is fired?
    is .selstart = 0 right before the first character
    and is .selstart = 3 possible?

    i guess if i have a textbox footext and then do
    do
    VB Code:
    1. footext.selstart = 2

    followed by

    VB Code:
    1. footext.text = "test"

    the .selstart value resets itself, correct?

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: getting the last textbox that was focussed on and placing the focus on it

    1)yes, the validate fires as soon as you try to leave the textbox
    2) the sellength is just setting how many characters to Select (Highlight)

    you can set selstart anywhere in the textbox
    selstart just places the cursor in that position

    and yes, if you set selstart = 2 then change the text in the textbox, selstart goes back to 0
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: getting the last textbox that was focussed on and placing the focus on it

    thanks for clearing my misunderstandings static

Posting Permissions

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



Click Here to Expand Forum to Full Width