Results 1 to 6 of 6

Thread: How to set back focus on a command button after it looses it due to some event

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    How to set back focus on a command button after it looses it due to some event

    Hi All,
    I have 4 command buttons commandbutton1 - 4 on my excel 'Sheet8'.
    I want Bold-Font for whichever of the buttons 1 - 3 get focus.
    Button 4 is just a settings button that doesn't need focus, it basically Opens up a UserForm when clicked.

    I defined LostFocus() for buttons 1-3 and they work fine. They basically sort my columns for some names.

    Now, when i click button 1, it gets focus, Bolds out its font, sorts out my columns on name "GGG". BUttons 2,3 work the same. But when i click button 4:

    1) Last Button from 1-3 looses focus, UnBolds its font.(Expected)
    2) UserForm opens, i click OK button to close it.
    3) Now, none of my Buttons from 1-3 are selected, but my sheet is still shorted on one of my last active Buttons from 1-3.

    I want one of the 3 buttons to either maintain its bold text, or regain focus back on closing UserForm, dunno how to identify the last active CommandButton before clicking Commandbutton4. How do i do that?


    thanks

    Mamu

  2. #2

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to set back focus on a command button after it looses it due to some event

    declare a variable in the general section at the top of the codepane for sheet8
    when buttons 1 to 3 are clicked set the variable
    when the userform is closing setfocus to the command button based on the variable
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: How to set back focus on a command button after it looses it due to some event

    I got that fixed, now the problem is, when i click anywhere on the sheet, my command buttons loose focus. Or when i click other buttons on the sheet (other than above 4 command buttons), same thing happens. How do i get to hold focus on those 3 command buttons in this situation?

    Thank for replying Pete?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to set back focus on a command button after it looses it due to some event

    perhaps you should look at replacing the command buttons with togglebuttons they probably do what you want by default
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: How to set back focus on a command button after it looses it due to some event

    Thanks westconn1, i really like this idea, this would make my life lot easier.

Tags for this Thread

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