Make a button on a tab control focused so you can hit the Space Bar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdamOnAccess
    New Member
    • Aug 2008
    • 99

    #1

    Make a button on a tab control focused so you can hit the Space Bar

    I am trying to set the focus on a button that sits on page 1 of my tab control. It looks like I'm successful at setting the focus because I see the highlight on the button, but when I push the space-bar, I get the sub menu for the main form; the button does not press down. I notice that when I click on the tab control, the highlighted button takes on an "added highlight". It looks like a dotted line over the original highlight. If I press the space-bar after this additional highlight appears, the button presses properly. Here is the code I'm using now to set the focus to the button on the tab control...

    Me!tabAllTabs.P ages(0).Control s!cmdAddNote.Se tFocus

    How do I get that button to the point that I only need to hit the space-bar to press it, without clicking on the tab control?

    ... and what is this additional state called? I thought that once you set the focus on a button, you needed only press space or enter to engage it.

    Thanks,
    Adam
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Controls on tabs are referred to the same way as controls on the main form. You should be able to use from main form code:
    Code:
    cmdAddNote.SetFocus

    Comment

    • topher23
      Recognized Expert New Member
      • Oct 2008
      • 234

      #3
      I just did some research on this, and what I learned is kind of interesting.

      First off, though, may I say I'd never seen anyone refer to a control on a tab control page through the controls collection of the page. I would never have even thought of it.

      It appears that, when referencing the control through the route described, the control doesn't receive the focus until the page receives the focus, due to the way the reference is called. It's sort of like when you have focus on a control in one form, then open another form. When the second form opens, the control that had the focus in the old form is still selected, but it won't actually get the focus unless that form becomes the active form.

      So, by referencing it in that method, you've in essence selected it, but are unable to give it the actual "focus" unless the page is given focus. If you set the focus for the control directly through the form, which is active and has focus, then focus is on that control immediately.

      Comment

      • AdamOnAccess
        New Member
        • Aug 2008
        • 99

        #4
        ChipR, Topher23,

        Thank you both for the response.

        ChipR, I originally tried what you suggested and got the same result; the button was selected but still did not respond to the space-bar as a push.

        Topher,
        Your description of how it works sounds right to me, but I still can't get it to work.

        I've tried this...
        Code:
        Me!cmdAddNotes.SetFocus
        and this...
        Code:
        Me!tabAllTabs.Pages(0).Controls!cmdAddNotes.SetFocus
        and this...
        Code:
        Me.SetFocus 'set focus to form first
        Me!cmdAddNotes.SetFocus
        and this...
        Code:
        Me!tabAllTabs.Pages(0).SetFocus 'set focus to tab control page 1 first
        Me!cmdAddNotes.SetFocus
        ... all generate the same result; the button is selected, but it will not respond to a "push" from the space-bar or enter-key until the form is actually clicked.

        Here's a little more info: I'm trying to set this in an event procedure generated from the Web Browser Control, Document Complete Event...
        Code:
        Private Sub wbbWebsite_DocumentComplete(ByVal pDisp As Object, URL As Variant)
            Me!txbPageTitle = Me!wbbWebsite.LocationName
           
            'Me!cmdAddNotes.SetFocus
        
            'Me!tabAllTabs.Pages(0).Controls!cmdAddNotes.SetFocus
        
            Me.SetFocus
            Me!cmdAddNotes.SetFocus
        End Sub
        The results are always the same. The button is selected, but does not respond to the enter button or space bar until I click on the form. I can't get it to work.
        Last edited by NeoPa; Nov 29 '09, 06:15 PM. Reason: Please use the [CODE] tags provided.

        Comment

        • ChipR
          Recognized Expert Top Contributor
          • Jul 2008
          • 1289

          #5
          Well, I'm stuck. I wanted to try this out with the Web Browser Control, but I can't find it in Access 2007.

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            Originally posted by ChipR
            Well, I'm stuck. I wanted to try this out with the Web Browser Control, but I can't find it in Access 2007.
            It's there, you are just not looking hard enough :).

            Look under the ActiveX components and then Microsoft Web Browser.

            You may also need to make a reference to the Microsoft HTML Controls

            cheers,

            Comment

            • AdamOnAccess
              New Member
              • Aug 2008
              • 99

              #7
              Ok, apparently this has nothing to do with the tab control. I tried to set focus to a button on the main form and I have the same problem: The button is selected but it does not respond to a push from either the enter key or the space bar. It will only respond after I click on the form.

              Thanks for all the help,
              Adam

              Comment

              • mshmyob
                Recognized Expert Contributor
                • Jan 2008
                • 903

                #8
                Originally posted by AdamOnAccess
                Ok, apparently this has nothing to do with the tab control. I tried to set focus to a button on the main form and I have the same problem: The button is selected but it does not respond to a push from either the enter key or the space bar. It will only respond after I click on the form.

                Thanks for all the help,
                Adam
                I haven't tried the problem you are having yet but if you do not need to manually press the key why don't you use the sendkey function to simulate pressing the button? Will that be satisfactory for you?

                cheers,

                Comment

                • mshmyob
                  Recognized Expert Contributor
                  • Jan 2008
                  • 903

                  #9
                  I just tried the scenario with a main form/ sub form and had same problem. But then I used the sendkeys statement and it worked.

                  sendkeys "{ENTER}" did the trick for me after setting focus to the button.

                  cheers,

                  Comment

                  • ChipR
                    Recognized Expert Top Contributor
                    • Jul 2008
                    • 1289

                    #10
                    I'm still suspicious of the web browser control, but I don't have a Microsoft HTML Controls reference to enable. The Microsoft HTML Objects reference didn't help. Anyone know if there's something I have to download?

                    Comment

                    • topher23
                      Recognized Expert New Member
                      • Oct 2008
                      • 234

                      #11
                      This may have something to do with Access being a bit mentally challenged when it comes to moving between containers. I'd guess the focus gets "stuck" when moving between the container and the main form.

                      SENDKEYS is one option, as mshmyob pointed out, or you could just run the code you need directly from the DocumentComplet e event, rather than clicking the button.

                      Comment

                      • AdamOnAccess
                        New Member
                        • Aug 2008
                        • 99

                        #12
                        Thanks all,

                        If wanted to call the button's subroutine every time, I would just call the routine right from the Document Complete event. But in this case, the user has to make a decision. Nine out of ten times, they will likely just push the button and move on - so I wanted to make it easy for them and set the focus to the button so they could just hit the space bar and keep going; however, depending on what comes up in the web control browser, they may not want to hit the button and move on.

                        The form is set up so the user doesn't have to use the mouse too much. These users prefer hot keys.

                        If I'm going to use the SENDKEYS option (something I don't think I've ever used before because I always set the hot key in the button's caption with the & symbol), I'll probably have to trap the key and prevent actions in cases where I don't want the button to perform any action.

                        I'll keep playing with it and see what I come up with.

                        Thank you all for your help.
                        -Adam

                        Comment

                        • AdamOnAccess
                          New Member
                          • Aug 2008
                          • 99

                          #13
                          I just tried:

                          Me!cmdAddNotes. SetFocus
                          SendKeys "{Enter}"

                          It selected the button, then I got a "Conk" noise - indicates that the Enter key did not take.

                          Is there a way to simulate a click on the form? Something like a Me.MouseClick

                          I think that would do it.
                          -Adam

                          Comment

                          • AdamOnAccess
                            New Member
                            • Aug 2008
                            • 99

                            #14
                            I'm out of ideas...

                            Besides a click on the form, nothing will give the buttons on the form "full focus". Not even hitting tab. Setfocus puts my form into a weird kind of "limbo" and the only way to get the form to work is to click it.

                            If anyone can figure out how to beat this, please let me know.
                            -Adam

                            Comment

                            • ChipR
                              Recognized Expert Top Contributor
                              • Jul 2008
                              • 1289

                              #15
                              What is the focus on prior to tyring to do this?

                              Comment

                              Working...