+ Reply to Thread
Results 1 to 8 of 8

Taking focus off control on sheet

  1. #1
    Don Wiss
    Guest

    Taking focus off control on sheet

    In my code I have used various methods to get the focus off of a Control
    Toolbox control, like a combo box or check box. One I use is:

    SendKeys "{ESC}"

    I don't think that this is the best. But I can't find in all of the code
    I've written what the other methods I've used are.

    Don <www.donwiss.com> (e-mail link at home page bottom).

  2. #2
    Dave Peterson
    Guest

    Re: Taking focus off control on sheet

    activesheet.range("a1").select

    (choose a cell of your choice?)

    Don Wiss wrote:
    >
    > In my code I have used various methods to get the focus off of a Control
    > Toolbox control, like a combo box or check box. One I use is:
    >
    > SendKeys "{ESC}"
    >
    > I don't think that this is the best. But I can't find in all of the code
    > I've written what the other methods I've used are.
    >
    > Don <www.donwiss.com> (e-mail link at home page bottom).


    --

    Dave Peterson

  3. #3
    Don Wiss
    Guest

    Re: Taking focus off control on sheet

    On Thu, 03 Aug 2006, Dave Peterson <[email protected]> wrote:

    >Don Wiss wrote:
    >>
    >> In my code I have used various methods to get the focus off of a Control
    >> Toolbox control, like a combo box or check box. One I use is:
    >>
    >> SendKeys "{ESC}"
    >>
    >> I don't think that this is the best. But I can't find in all of the code
    >> I've written what the other methods I've used are.


    >activesheet.range("a1").select
    >
    >(choose a cell of your choice?)


    No. That is the worst way of doing it. You don't know where their cursor is
    on the sheet and you want to put it back where it was. And you don't want
    the sheet to move.

    I had two more I used. One was something about an active window.

    Don <www.donwiss.com> (e-mail link at home page bottom).

  4. #4
    Registered User Ivan F Moala's Avatar
    Join Date
    10-25-2003
    Location
    Auckland, New Zealand
    Posts
    71
    one possible way ??

    '// Worksheet code module

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On error resume next
    Set Rg = Target
    End Sub


    '// Std Module

    Public Rg As Range

    Sub DoSel()
    On Error Resume Next
    Rg.Select
    End Sub


    '// called via your controls code @ the End of the controls code


    eg Checkbox code

    Private Sub CheckBox1_Click()
    DoSel
    End Sub
    Kind Regards,
    Ivan F Moala From the City of Sails
    \1

  5. #5
    Dave Peterson
    Guest

    Re: Taking focus off control on sheet

    You should have included more details of what you wanted in your original post.

    Don Wiss wrote:
    >
    > On Thu, 03 Aug 2006, Dave Peterson <[email protected]> wrote:
    >
    > >Don Wiss wrote:
    > >>
    > >> In my code I have used various methods to get the focus off of a Control
    > >> Toolbox control, like a combo box or check box. One I use is:
    > >>
    > >> SendKeys "{ESC}"
    > >>
    > >> I don't think that this is the best. But I can't find in all of the code
    > >> I've written what the other methods I've used are.

    >
    > >activesheet.range("a1").select
    > >
    > >(choose a cell of your choice?)

    >
    > No. That is the worst way of doing it. You don't know where their cursor is
    > on the sheet and you want to put it back where it was. And you don't want
    > the sheet to move.
    >
    > I had two more I used. One was something about an active window.
    >
    > Don <www.donwiss.com> (e-mail link at home page bottom).


    --

    Dave Peterson

  6. #6
    Dave Peterson
    Guest

    Re: Taking focus off control on sheet

    ps. maybe something like:

    Option Explicit
    Private Sub ComboBox1_Change()
    ActiveCell.Activate
    'your code here
    End Sub

    If you're using a control (like a commandbutton from the control toolbox
    toolbar), you can change the .takefocusonclick property to false.

    Dave Peterson wrote:
    >
    > You should have included more details of what you wanted in your original post.
    >
    > Don Wiss wrote:
    > >
    > > On Thu, 03 Aug 2006, Dave Peterson <[email protected]> wrote:
    > >
    > > >Don Wiss wrote:
    > > >>
    > > >> In my code I have used various methods to get the focus off of a Control
    > > >> Toolbox control, like a combo box or check box. One I use is:
    > > >>
    > > >> SendKeys "{ESC}"
    > > >>
    > > >> I don't think that this is the best. But I can't find in all of the code
    > > >> I've written what the other methods I've used are.

    > >
    > > >activesheet.range("a1").select
    > > >
    > > >(choose a cell of your choice?)

    > >
    > > No. That is the worst way of doing it. You don't know where their cursor is
    > > on the sheet and you want to put it back where it was. And you don't want
    > > the sheet to move.
    > >
    > > I had two more I used. One was something about an active window.
    > >
    > > Don <www.donwiss.com> (e-mail link at home page bottom).

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

  7. #7
    Don Wiss
    Guest

    Re: Taking focus off control on sheet

    On Fri, 04 Aug 2006, Dave Peterson <[email protected]> wrote:

    >Option Explicit
    >Private Sub ComboBox1_Change()
    > ActiveCell.Activate
    > 'your code here
    >End Sub


    Yes, that looks like it would work.

    Thinking about where I have done this before I found this one:

    Range(ActiveCell.Address).Select

    Then I think the other I've used was something like: ActiveWindow.Activate

    I gather any of these are better than sending an escape.

    >If you're using a control (like a commandbutton from the control toolbox
    >toolbar), you can change the .takefocusonclick property to false.


    (1) I never use a button from the Control toolbox. I see no advantages.

    (2) I do use ComboBoxes, CheckBoxes, and OptionButtons, usually as I want
    to be able to hide them. For some reason not all of the Forms controls are
    hideable.

    I did not find the .takefocusonclick property on the ComboBox properties
    list. That is the only control I had a chance to check.

    Don <www.donwiss.com> (e-mail link at home page bottom).

  8. #8
    Tom Ogilvy
    Guest

    Re: Taking focus off control on sheet

    Range(ActiveCell.Address).Select
    would be redundant compared to
    ActiveCell.Activate
    or
    Selection.Select

    and if the user had multiple cells selected, would not disturb them as your
    choice would.

    CommandButton is the only control that has a takefocusonclick property.

    --
    Regards,
    Tom Ogilvy

    "Don Wiss" <donwiss@no_spam.com> wrote in message
    news:[email protected]...
    > On Fri, 04 Aug 2006, Dave Peterson <[email protected]> wrote:
    >
    >>Option Explicit
    >>Private Sub ComboBox1_Change()
    >> ActiveCell.Activate
    >> 'your code here
    >>End Sub

    >
    > Yes, that looks like it would work.
    >
    > Thinking about where I have done this before I found this one:
    >
    > Range(ActiveCell.Address).Select
    >
    > Then I think the other I've used was something like: ActiveWindow.Activate
    >
    > I gather any of these are better than sending an escape.
    >
    >>If you're using a control (like a commandbutton from the control toolbox
    >>toolbar), you can change the .takefocusonclick property to false.

    >
    > (1) I never use a button from the Control toolbox. I see no advantages.
    >
    > (2) I do use ComboBoxes, CheckBoxes, and OptionButtons, usually as I want
    > to be able to hide them. For some reason not all of the Forms controls are
    > hideable.
    >
    > I did not find the .takefocusonclick property on the ComboBox properties
    > list. That is the only control I had a chance to check.
    >
    > Don <www.donwiss.com> (e-mail link at home page bottom).




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1