Event based on tab rotation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ducknut
    New Member
    • Jul 2006
    • 11

    Event based on tab rotation

    Hi all,

    I have a procedure that will execute on a "on exit" event, but I only want it to fire when you exit by hitting the Tab button. I don't want it to fire when focus is lost by hitting Shift+Tab or by clicking a different control.

    Any suggestions?

    Thanks.

    DuckNut
  • BSOB
    New Member
    • Jul 2006
    • 77

    #2
    ok, im sure there are (much) better ways to do this, and people like sashi (that actually know how) will come in right behind me and give you the easier, faster, more logical method. but until then, heres how i would go about this:

    the keydown event does not register when tab is pressed. (but you already knew that, or you wouldnt be asking)
    so i would create an object (any object, as long as it can receive focus, like a text box, or command button. im going to assume a text box)
    place the text box off the screen (left = -100, top = -100) but visible property = true, or else it can not recieve focus.
    set the tabindex of your new text box to be one greater than the textbox in question (the one loosing focus)
    on the getfocus event of your new text box, do your stuff and then send the fucus to the next logical object.

    it isnt pretty. but it isnt difficult.

    Comment

    • Ducknut
      New Member
      • Jul 2006
      • 11

      #3
      Thanks for the response. It works.......but . Now when I have to move backwards through the form by shift+tab it stalls at the new text box. When I shift+tab back, the text box gets focus again and the code fires, setting the focus back to the text box I just left.



      Originally posted by BSOB
      ok, im sure there are (much) better ways to do this, and people like sashi (that actually know how) will come in right behind me and give you the easier, faster, more logical method. but until then, heres how i would go about this:

      the keydown event does not register when tab is pressed. (but you already knew that, or you wouldnt be asking)
      so i would create an object (any object, as long as it can receive focus, like a text box, or command button. im going to assume a text box)
      place the text box off the screen (left = -100, top = -100) but visible property = true, or else it can not recieve focus.
      set the tabindex of your new text box to be one greater than the textbox in question (the one loosing focus)
      on the getfocus event of your new text box, do your stuff and then send the fucus to the next logical object.

      it isnt pretty. but it isnt difficult.

      Comment

      • BSOB
        New Member
        • Jul 2006
        • 77

        #4
        lol. ok, i handnt thought of tabing the other way onto it. are you ready for some more not-so-pretty code?
        terms that i will use:
        text2 > the textbox loosing focus (tab index 1)
        text1 > the invisible text box (tab index 2)
        command1 > the next logical tab index control (tab index 3)

        Dim FocusFromContro l as boolean
        sub text2_lost focus()
        FocusFromContro l = true
        end sub
        sub text1_get focus()
        if focusfromcontro l then
        <"your stuff">
        command1.setfoc us
        else
        text2.setfocus
        end if
        end sub
        sub command1_lost focus()
        focusfromcontro l = false
        end sub

        if people are tracking my posts they will have been getting quite the idea of my programming style; "whatever works"

        Comment

        • Ducknut
          New Member
          • Jul 2006
          • 11

          #5
          That seems to work!

          Thanks for the response.

          DuckNut

          Comment

          Working...