473,320 Members | 1,993 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,320 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 8024
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.