473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.Pages(0).Controls!cmdAddNote.SetFocu s

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
Nov 24 '09 #1
21 4771
ChipR
1,287 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. cmdAddNote.SetFocus
Nov 24 '09 #2
topher23
234 Expert 100+
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.
Nov 25 '09 #3
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...
Expand|Select|Wrap|Line Numbers
  1. Me!cmdAddNotes.SetFocus
and this...
Expand|Select|Wrap|Line Numbers
  1. Me!tabAllTabs.Pages(0).Controls!cmdAddNotes.SetFocus
and this...
Expand|Select|Wrap|Line Numbers
  1. Me.SetFocus 'set focus to form first
  2. Me!cmdAddNotes.SetFocus
and this...
Expand|Select|Wrap|Line Numbers
  1. Me!tabAllTabs.Pages(0).SetFocus 'set focus to tab control page 1 first
  2. 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...
Expand|Select|Wrap|Line Numbers
  1. Private Sub wbbWebsite_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  2.     Me!txbPageTitle = Me!wbbWebsite.LocationName
  3.  
  4.     'Me!cmdAddNotes.SetFocus
  5.  
  6.     'Me!tabAllTabs.Pages(0).Controls!cmdAddNotes.SetFocus
  7.  
  8.     Me.SetFocus
  9.     Me!cmdAddNotes.SetFocus
  10. 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.
Nov 25 '09 #4
ChipR
1,287 Expert 1GB
Well, I'm stuck. I wanted to try this out with the Web Browser Control, but I can't find it in Access 2007.
Nov 25 '09 #5
mshmyob
904 Expert 512MB
@ChipR
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,
Nov 25 '09 #6
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
Nov 25 '09 #7
mshmyob
904 Expert 512MB
@AdamOnAccess
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,
Nov 25 '09 #8
mshmyob
904 Expert 512MB
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,
Nov 25 '09 #9
ChipR
1,287 Expert 1GB
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?
Nov 25 '09 #10
topher23
234 Expert 100+
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 DocumentComplete event, rather than clicking the button.
Nov 25 '09 #11
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
Nov 25 '09 #12
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
Nov 25 '09 #13
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
Nov 25 '09 #14
ChipR
1,287 Expert 1GB
What is the focus on prior to tyring to do this?
Nov 25 '09 #15
Typically, original focus is on the form...

I have a form with a recordset of URLs. Each time I advance to a new record, the OnCurrent Event triggers:

Me!wbbWebControl.LocationUrl strUrl

wbbWebControl loads the Url and triggers the DocumentComplete event. In the document complete event is:

Me!cmdNotes.SetFocus

cmdNotes gets the focus (I see it highlighted) but it will not respond to the enter key, the space-bar, the hotkey in the caption name ("&Notes") and even the tab button will not move the focus. Nothing happens until you click on the form.
-Adam
Nov 25 '09 #16
topher23
234 Expert 100+
Wow, there's very little information about this anywhere. This appears to be somewhat unique to the WebBrowser control. I was able to track down one other similar situtation, which had no resolution. However, a lot of playing with a mockup I made with a WebBrowser control, a button and a text box revealed something interesting. If you pay very close attention to the control that you are trying to set the focus to, you can sometimes see that, for just an instant, it does have the focus - and then the WebBrowser control snatches it. Oddly, the WebBrowser control doesn't put the focus on the web page, but just leaves it hanging in limbo in the ActiveX container. Experimenting with different control properties was fruitless. I'm starting to think that MS had some reason for programming it this way, they simply failed to tell anyone what that reason was. I suppose they would call it a "feature."
Nov 25 '09 #17
mshmyob
904 Expert 512MB
I have also looked around online and see that it is a problem for many but nobody has given a solution to the problem.

One thing that you need to watch is that your DocumentComplete event may be triggered many times if a site has frames. This event appears to be triggered for each frame. You would also need to use the ReadyState to determine when a site has fully loaded.

I'll keep fooling around and see what I can come up with if anything.

cheers,
Nov 25 '09 #18
topher23
234 Expert 100+
Very interesting. I'm posting from the WebBrowser object in my Access app right now. Kind of fun. Anyway, it turns out the WebBrowser object is, in fact, giving itself focus. The object itself is an instance of an outside program, so when it steals the focus, the last focus given control in Access still has focus in Access. At this point, you're not in Access anymore - you're in an instance of the WebBrowser ActiveX object. Web browsers are primarily mouse-based, which may be the cause of the problem we're having here. Until you click on something on the web page that's displayed, nothing will have focus, so it seems like the focus has "vanished." However, it appears the only way to take the focus back to Access from the WebBrowser control is also through a mouse-click. Also, the Enter key doesn't seem to do anything inside the WebBrowser control, which is why this is all in one great block.
Nov 25 '09 #19
Well, I'm exhausted. I've tried to see if there was a way to send a mouse click through sendkeys, and I found some stuff on it, but nothing beat this problem. Topher23, I did see the button get full focus, but then get pulled back as you described. It leads me to believe that the web browser control might have some other event after the documentComplete that is pulling the focus back. I've tried to figure out what that event might be, but no luck.

This one has me stumped.
Nov 27 '09 #20
NeoPa
32,556 Expert Mod 16PB
I don't have one to play with Adam, but have you tried (in code) selecting, first the main form, then (if you have one involved) the subform, then the page and lastly, the control. Topher's earlier explanation is why this is an issue I'm sure. I hope that this sequence will be a workable solution.

I just finished catching up on all the recent posts which indicate this may not work. May be worth a try, but doubtful if I'm honest :(
Nov 29 '09 #21
NeoPa,

Thanks, but I've tried all kinds of games with it and nothing has worked. I tried what you suggested and that didn't work. I came close when I set the web control enable=false immediately after I set the focus to the button. The button did get the proper focus, but the entire form froze. :(

It's time for me to let this issue go. Thanks for looking into it.
-Adam
Nov 29 '09 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason Kyle Baginski | last post by:
Here's a little test app to demonstrate a problem I'm having. It creates four buttons, each one with the different FlatStyle types available. Three of them behave exactly the same way(and the...
18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
2
by: jrhoads23 | last post by:
If you look at a standard Button in a .NET Windows Forms app, you will notice its default BackColor is "Control" and it has a 3D raised border which is 2 pixels wide. The outer edge on the left and...
2
by: David Cho | last post by:
After the user fills out the webform, my customer would like a default button on the form to have focus, so that all the user has to do is press <enter> as opposed to having to take the cursor and...
12
by: SJ | last post by:
Hope someone can help me out there I'm struggling with a particular problem... I have a form with many tab pages. On one tab page I've got a button which when clicked with a mouse adds items...
3
by: Boni | last post by:
Dear all, if I have a Form and some controls on it, how can I get a pointer to the focused control. I what to remember focused control, do some operations and then restore focus
1
by: Gary | last post by:
There are several controls in my form. How to detect currently which control has the forcus and set the forcus to a certain control? Thanks,
0
by: gnewsgroup | last post by:
A aspx page of mine contains a user control in a Panel control. This user control has a textbox, a search button and a cancel button like this: btnSearch btnCancel When btnSearch is...
3
pentahari
by: pentahari | last post by:
In VB6, I have created the form look like the message box. but one problem has occurred that the one button had already focused but the rectangle focus symbol appeared on the focused button. But the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.