Backtabbing between SubForms on TabControls

B

blueboxturtle

Hi,
I am a novice Access2003 developer working on several databases, most of
which involve data entry into a main form that uses a large tab control to
organize many other subforms, some of which have their own tab controls with
subforms on them and others of which are simply subforms that can scroll
downward to display all the entry fields. Access table size limitations
dictated the need for many subforms, each having its own table.

The application will be used in a data entry setting and I would like to
minimize situations where the entry person has be to slowed down by having to
reach away from the keyboard and click a mouse. For this reason I have been
adding code to facilitate some minimal backwards (shift-tab) and forward (tab
or enter) keyboard implemented moves to augment the usual between-control
movements within a page or form.

I am setting the KeyPreview event property to Yes. I am setting the Cycle
property of all forms involved to be "Current Record." I am using the
typical code (found in the O'Reilly Access Cookbook among others) for
capturing user keystrokes on the KeyDown event and I also found that using
the AfterUpdate event has seemed to work best for those times when data has
been actually entered.

Within each tab page or form the cursor moves forward and backward through
the control cycle easily and normally. The event code is only needed to
smooth the cursor movement up and down the parent, child and grandchild
subform tree and across the tab control boundary so that focus won't stop on
a tab of the tab-control itself.
Diagram:
Main Form
Tab Control on Main Form
TabCwithSubform, TabDwithSubform, TabEwithSubform

There's a lot of code but a typical simpler example would be similar to this:

'YOU ARE IN THE PART D SUBFORM CODE

'Move focus after update from child subform D
' to child subform E on next tab of Main
Private Sub LASTFIELD_ON_PART_D_SUBFORM_AfterUpdate()
KeyCode = 0
Forms![subfrm_Main].SetFocus
Forms![subfrm_Main]![subfrm_Child_E].SetFocus
Forms![subfrm_Main]![subfrm_Child_E]!FIRSTFIELD_ON_PART_E.SetFocus
End Sub

'Move focus after tab or enter from child subform D
' to child subform E on next tab of Main
Private Sub LASTFIELD_ON_PART_D_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intShiftDown As Integer
inShiftDown = (Shift And acShiftMask) > 0
On Error Resume Next
Select Case KeyCode
Case (vbKeyTab And Not intShiftDown)
KeyCode = 0
Forms![subfrm_Main].SetFocus
Forms![subfrm_Main]![subfrm_Child_E].SetFocus
Forms![subfrm_Main]![subfrm_Child_E]!FIRSTFIELD_ON_PART_E.SetFocus
Case vbKeyReturn
KeyCode = 0
Forms![subfrm_Main].SetFocus
Forms![subfrm_Main]![subfrm_Child_E].SetFocus
Forms![subfrm_Main]![subfrm_Child_E]!FIRSTFIELD_ON_PART_E.SetFocus
Case Else
'Do Nothing.
End Select
End Sub

-------------- the above type of code works great -------

To move backward I can use code like this:

'Handle a shift back from child subform D
' to child subform C
Private Sub FIRSTFIELD_ON_PART_D_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intShiftDown As Integer
intShiftDown = (Shift And acShiftMask) > 0
On Error Resume Next
Select Case KeyCode
Case (vbKeyTab And intShiftDown)
KeyCode = 0
Forms![subfrm_Main].SetFocus
Forms![subfrm_Main]![subfrm_Child_C].SetFocus
Forms![subfrm_Main]![subfrm_Child_C]!LASTFIELD_ON_PART_C.SetFocus
Case Else
'Do Nothing.
End Select
End Sub

The above type of backward-moving code works great IF the subform you are
moving FROM does NOT have a tab-control structure on it. But here's (to me!)
the weird thing:
If the subform you are moving from has a tab-control on it, the above
backward-moving code won't work. This is -regardless- of whether the field
you are leaving (the one whose KeyDown event you tie to) is inside the
tab-control or not. And, it only effects Shift-Tab (backwards moving) code,
not forward moving tab or enter type code. What happens when it doesn't work
is that the cursor actually moves -forward- one control on the same form
rather than moving backward to the previous subform on the previous tab of
the main form. The above backward moving code would of course just be
another case statement in the KeyDown Sub in many cases.

blueboxturtle
 
B

blueboxturtle

I sometimes feel that all the posts about adding a "1 twip" tiny control just
as one more place to tab to on a form might somehow be involved in the
answer. Or sometimes I feel I should be studying one of the pages of "Order
of Events" documentation but overall I'm still frustrated by not
understanding this!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top