Tabbing through subforms? (1 Viewer)

Heatshiver

Registered User.
Local time
Tomorrow, 03:48
Joined
Dec 23, 2011
Messages
263
I have two subforms on a main form. I was wondering if there was a way to capture the tab key so that when they reach the last field on the first subform it will tab them into the first field of the second subform?

What I have so far is to turn on the KeyPreview in the first subform's load function. I then use the KeyDown event on the last field of the first subform. I then have the following code:

Code:
Select Case KeyCode
    Case vbKeyTab
        Forms![frmMudCop].[fsubSolidCtrlSum2].Form.[ScreenSize(CD12)].SetFocus
    Case Else
End Select
The code runs without an error, but instead continues on to the next field in that subform... Any help is much appreciated!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:48
Joined
Aug 30, 2003
Messages
36,132
Not sure it matters, but I use the KeyPress event.
 

Heatshiver

Registered User.
Local time
Tomorrow, 03:48
Joined
Dec 23, 2011
Messages
263
Tried it, but same result... Thanks though.
 

Heatshiver

Registered User.
Local time
Tomorrow, 03:48
Joined
Dec 23, 2011
Messages
263
Moreorless I just need to capture the TAB key and make it perform CTRL+TAB...
 

Heatshiver

Registered User.
Local time
Tomorrow, 03:48
Joined
Dec 23, 2011
Messages
263
I have found they keycodes for CTRL and TAB, but using them in combination for the code seems to do nothing. Everything I can find on the net doesn't seem to show using to keycodes together, just how to disable ones (normally with ALT involved)...
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:48
Joined
Aug 30, 2003
Messages
36,132
Since you're setting focus to a subform, often you need two lines, the first setting focus to the subform itself, the second to the desired control.
 

Heatshiver

Registered User.
Local time
Tomorrow, 03:48
Joined
Dec 23, 2011
Messages
263
@pbaldy - So your thought was definitely the right track. My code is now like this:
Code:
Select Case KeyCode
    Case vbKeyTab
        Forms![frmMudCop].[fsubSolidCtrlSum2].SetFocus
        Forms![frmMudCop].[fsubSolidCtrlSum2].Form.[ScreenSize(CD12)].SetFocus
    Case Else
End Select
The only issue I'm having is that now it skips the first field, "ScreenSize(CD12)", and goes straight to the second field in the subform. This happens whether or not I have the code to SetFocus on "ScreenSize(CD12)"...

Thanks for the help!
 

Heatshiver

Registered User.
Local time
Tomorrow, 03:48
Joined
Dec 23, 2011
Messages
263
Bit of an update. Tried SetFocus to the second field on the second subform. All this did was make it SetFocus to the third field...

Also tried setting "ScreenSize(CD12)" to TabIndex = 0 - even though it already is - but still produces the same result.

The way I had to fix this was that I first realized I had put a box inside the second subform because of a SetFocus I had before with it. The field did not allow a Tab stop. I replaced "ScreenSize(CD12)" with that field and now it works perfectly!

Thanks for all the help! Much appreciated!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:48
Joined
Aug 30, 2003
Messages
36,132
Glad you got it sorted out.
 

Users who are viewing this thread

Top Bottom