Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Aug 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Click events and Got Focus events (2K)

    I have some code in the 'Got Focus' event of a control. When the control is passed the focus, nothing happens. When I click on that control though, all the code gets executed. Why would there be a difference between the control being passed the focus and being clicked on. ( totally different code for the click event, and of course that all works ) Why won't it recognize the Got and Lost focus events by themselves?

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Click events and Got Focus events (2K)

    It should work. In the property sheet, are you sure the OnGotFocus property has [Event Procedure] in it?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Lounger
    Join Date
    Aug 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Click events and Got Focus events (2K)

    yes, it does.

  4. #4
    Lounger
    Join Date
    Aug 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Click events and Got Focus events (2K)

    Interestingly, if the control loses the focus because I hit the 'Tab' button then all the code gets executed. It only doesn't work if the control loses the focus because I've clicked on another control. The wierd part - - The code that's in the 'Got Focus' section only gets executed when the control loses the focus. Perhaps when you use 'ControlName.SetFocus' that isn't the same as getting the focus to to the tab stop property?

  5. #5
    Lounger
    Join Date
    Aug 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Click events and Got Focus events (2K)

    Everything works fine if I use the Tab button to get the focus to the control with all the code. The only circumstance where it doesn't work is if I use the SetFocus property from the code in a previous control. Clearly I'm doing something silly, but what???

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Click events and Got Focus events (2K)

    You're just running into the way events work. For example, if you click on a button, the Click event of the button happens BEFORE the LostFocus or Exit event of the control you were just in. That means you can't depend on LostFocus in all circumstances. If you SetFocus from code, it won't trigger the events that tabbing into the control trigger, so you may have to use a different event depending on what exactly you're trying to do. One workaround is to set the focus in code and then explicitly call the event procedure you need to trigger, for example:

    Me!txtSomething.SetFocus
    Call txtSomething_GotFocus

    Just keep in mind that you may have to play with your code to get a sequence of events that Access will accept.
    Charlotte

Posting Permissions

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