Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setfocus not working (97 )

    I have a text box, set to tab 0, so the cursor enters the box on opening the form, some code set on the update event, the code at the end clears the textbox, and then i want to give the focus back to the text box again. the focus is shifting to the next combo box. So i kinda want the Combo boxes to work, but not to actually ever gain the focus.

    ie:

    Me!Search_Box=""

    Then i thought aha! all i have to do is add this, to give the control back to the text box. <img src=/S/clever.gif border=0 alt=clever width=15 height=15>

    Me!Search_Box!.SetFocus

    or perhaps

    Forms![Document Library]!Search_Box.SetFocus

    But No! <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> the Evil Access program ignores my pitiful attempts at controlling it, and just ignores the code completely, and gives the focus to the next combo box ! <img src=/S/aflame.gif border=0 alt=aflame width=16 height=16>

    I have a combo box to either side of this. And the user can use these as well, after each of these, i can do an afterupdate etc to give the focus back to the Search_Box in the middle, so that kind of works.


    I've placed my code to give the focus in allllll kinds of places, the logical place i thought would be when the combo box gains the focus, just switch it back to the Search_Box... well this actually works.. but makes the combo box not work, when you click on it to gain the focus, it just switches..



    Any .SetFocus experts out there....

    or even just good...

    or even just 'better than me'.... (oops thats everyone!)

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Edmonton, Alberta, Canada
    Posts
    326
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setfocus not working (97 )

    Not sure if this is what you mean, but if you don't want the user to be able to tab to the combo box, turn off "Tab Stop" in the properties of the combo box. If you don't want the user to be able to change the combo box, turn on "Locked". If you don't want the user to even be able to click in the combo box, turn off "Enabled" (if you don't like the ghosting effect, turn off "Enabled" AND turn on "Locked"). Although, if the user can't get there at all, a combo box seems rather pointless.

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Setfocus not working (97 )

    SetFocus normally works OK. You may want to post the code used for textbox's AfterUpdate event, otherwise it'd be hard to say why SetFocus isn't working correctly in this case.

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

    Re: Setfocus not working (97 )

    Access is trying to tell you something, Steve. This code should work (as should the other if you take out the extra bang (!) before the setfocus method):
    Forms![Document Library]!Search_Box.SetFocus

    However, if that control already has the focus, you'll get an error trying to set the focus there. GotFocus fires each time the control receives the focus, so if your combobox has code in its GotFocus event to set the focus somewhere else, there isn't any way to use the combobox or to set the focus to it and have it stick. You've effectively turned it into a ping pong ball that will keep merrily bouncing the focus back to wherever your code says for it to go.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setfocus not working (97 )

    If you are doing what I think you are doing, and using an unbound textbox then you can use the Before Update event and then use:-

    Cancel = True
    Me.Undo

    after your code to clear the box and remain in it.

    HTH

    Peter(_in_Kent) <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  6. #6
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setfocus not working (97 )

    Maaaany thanks peoples. will have another bash tomorrow and see if anything here works better. <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

Posting Permissions

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