473,387 Members | 1,711 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,387 software developers and data experts.

tabbing out of a subform without knowing about the parent

There have been threads in this newsgroup explaining how to
tab out of a subform to the parent form -- without having to
use ctrl-tab (of which users might be unaware -- and at any
rate, they shouldn't have to know that part of a form is
a "subform").

I use a common subform among two main forms, so those solutions
won't work -- because the "next control" depends on who the
parent is. And even if I write fancy code to detect which
parent I have, the subform code will break if I change the
parent's next control.

Here's my brilliant idea, which doesn't work: on the
last control of the subform, check KeyDown and change
TAB to CTRL+TAB, in hopes that Access will recognize it.

Private Sub <LASTCONTROL>_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab And Shift <> 1 Then
Shift = 2 ' change ordinary tab (or ctrl-tab) to ctrl-tab
to get out of subform
End If
End Sub

Alas, this does nothing; TAB cycles within the subform.
Maybe KeyDown simply can't pass CTRL+TAB to Access. But, if
if anybody sees a flaw in my code, please post it and we'll
have a wonderful way to TAB our way out of subforms!

Note: you'd have to do a similar check for SHIFT+TAB out of
the *first* control of the subform.

Nov 13 '05 #1
4 8033
On 8 Apr 2005 14:03:40 -0700, "Michael Fay" <fa*@acm.org> wrote:

Interesting idea.
Try using SendKeys instead.

-Tom.

There have been threads in this newsgroup explaining how to
tab out of a subform to the parent form -- without having to
use ctrl-tab (of which users might be unaware -- and at any
rate, they shouldn't have to know that part of a form is
a "subform").

I use a common subform among two main forms, so those solutions
won't work -- because the "next control" depends on who the
parent is. And even if I write fancy code to detect which
parent I have, the subform code will break if I change the
parent's next control.

Here's my brilliant idea, which doesn't work: on the
last control of the subform, check KeyDown and change
TAB to CTRL+TAB, in hopes that Access will recognize it.

Private Sub <LASTCONTROL>_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab And Shift <> 1 Then
Shift = 2 ' change ordinary tab (or ctrl-tab) to ctrl-tab
to get out of subform
End If
End Sub

Alas, this does nothing; TAB cycles within the subform.
Maybe KeyDown simply can't pass CTRL+TAB to Access. But, if
if anybody sees a flaw in my code, please post it and we'll
have a wonderful way to TAB our way out of subforms!

Note: you'd have to do a similar check for SHIFT+TAB out of
the *first* control of the subform.


Nov 13 '05 #2
Tom -- SendKeys works! (Mostly.) Now we're close. I fixed the Shift
mask checking and put in SendKeys calls for both the first and last
controls:

Private Sub <LASTCONTROL>_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab And ((Shift And acShiftMask) = 0) Then
SendKeys "^{TAB}" ' ctrl-tab moves out to the parent form!
End If
End Sub
Private Sub <FIRSTCONTROL>_KeyDown(KeyCode As Integer, Shift As
Integer)
If (KeyCode = vbKeyTab) And ((Shift And acShiftMask) > 0) Then
SendKeys "^+{TAB}" ' ctrl-shift-tab moves out backwards to
the parent form!
End If
End Sub

A problem remains: if you TAB your way out to the parent, then
immediately SHIFT-TAB back in, focus passes to the *first* control of
the subform, not the last one. I tried to fool Access with a .SetFocus
call before the SendKeys, but to no avail. Can anyone fix this? The
analogous problem occurs with SHIFT-TAB from the first control,
followed by TAB back in (to the last control).

Folks, if we can get this working perfectly it would make subforms
quite desirable in a number of circumstances:
- common portions of several main forms
- a subform can be attached to a different table from the main form --
in effect you are attaching to two tables, which is impossible
otherwise (without a bunch of awkward code, e.g. copying to a "hidden"
form).

Nov 13 '05 #3
Michael Fay wrote:
Tom -- SendKeys works! (Mostly.) Now we're close. I fixed the Shift
mask checking and put in SendKeys calls for both the first and last
controls:

Private Sub <LASTCONTROL>_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab And ((Shift And acShiftMask) = 0) Then
SendKeys "^{TAB}" ' ctrl-tab moves out to the parent form!
End If
End Sub
Private Sub <FIRSTCONTROL>_KeyDown(KeyCode As Integer, Shift As
Integer)
If (KeyCode = vbKeyTab) And ((Shift And acShiftMask) > 0) Then
SendKeys "^+{TAB}" ' ctrl-shift-tab moves out backwards to
the parent form!
End If
End Sub

A problem remains: if you TAB your way out to the parent, then
immediately SHIFT-TAB back in, focus passes to the *first* control of
the subform, not the last one. I tried to fool Access with a .SetFocus
call before the SendKeys, but to no avail. Can anyone fix this? The
analogous problem occurs with SHIFT-TAB from the first control,
followed by TAB back in (to the last control).

Folks, if we can get this working perfectly it would make subforms
quite desirable in a number of circumstances:
- common portions of several main forms
- a subform can be attached to a different table from the main form --
in effect you are attaching to two tables, which is impossible
otherwise (without a bunch of awkward code, e.g. copying to a "hidden"
form).

There might be an easy safer way to do this. Create a small text box
control on the subform, name it "txtSentry" or some such and make it
last in the tab order. Make it without a border and forecolor/backcolor
to match the Section's values.

Then add code to set focus to the parent for and then some control on
the parent form (I used txtName in this example):

Private Sub txtSentry_GotFocus()

Me.Parent.Form.SetFocus
Me.Parent.Form!txtName.SetFocus

End Sub

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #4
But this has the drawback of putting code in the subform that knows the
name of the next control in the parent form; I was trying to avoid that
kind of dependency.

Also, it looks like you couldn't shift-tab backwards across txtSentry.

This is tricky, isn't it?
- Mike Fay

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rob Tiemens | last post by:
hello, I need to select the first and the second column of a table. But I don't know the names of the columns. Is there any way I can select only the first column from a table without knowing...
24
by: gswork | last post by:
Let's write a c program, without knowing what it does... Some of you may recall Jim Roger's excellent series of posts (on comp.programming) exploring the implementation of common software...
2
by: AdamM | last post by:
Currently, my code reads from a database without knowing the order of the columns like this: string name = (string)datarow; However, is there a way to write or do an INSERT back to a database...
4
by: Charles Law | last post by:
Is there a way to dynamically remove an event handler from an event without knowing the name of the handler? For example, how can ClassB remove the handler without knowing the name, or how many...
3
by: farseer | last post by:
If i have an array of a certain type, is there away of initializing with without knowing it's type? for example (forgive me if some of this is syntactically incorrect) if i have a procedure...
3
by: Familjen Karlsson | last post by:
Here is an example from the help on the keword OleDbConnection, in VB.Net, they don't give the path to the database just the word localhost. How can it connect to the database without knowing where...
5
by: Luqman | last post by:
How can Administrator change the Password of existing User, without knowing his Old Password in Administer Security Tool ? One user has forgot his password, and Administer wants to refresh it. ...
11
by: John | last post by:
Hi I have a data row variable which could be for any of a number of tables in my apps. How can I type cast the variable to correct type at runtime? I know I can get the type description using...
2
by: Parmenides | last post by:
I get the "this record has been changed by another user since you started editing it" message when I first make an edit in a subform then click on anything in the parent area. It won't give me the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.