[AccessD] Your favorite control behavior

Jim Dettman jimdettman at earthlink.net
Wed Mar 10 08:12:23 CST 2004


<<>When it comes to subform tabbing you can store the tab index
(me.parent.tabindex), do a one time write of cursor navigation code for the
subform (for continuous forms for example) and at EOF, iterate the parent's
control's tab index properties and set focus to the next one so the user
doesn't know he was ever in a subform.

Sounds like one for the framework!  Thanks.>>

  Some code below that might help get that started.  This is really old code
(A2 days) so no comments on the style or the sendkeys use<g>.

Jim Dettman
President,
Online Computer Services of WNY, Inc.
(315) 699-3443
jimdettman at earthlink.net


Sub SubFormNavigate(ByVal wKeyCode As Integer, ByVal wShift As Integer, Frm
As Form, strParam As String)

' Receives : KeyCode representing which key was pressed
'            Shift indicating whether shift, alt, ctrl were pressed

' Returns  : Nothing (subroutine).

' Author   : Ian Sparks (Uk).
' Date     : 5th July 1994.

' Purpose  : This function is called from the start and end of single-value
subforms
'            and catches keystrokes like TAB to move off the current record.
It re-maps
'            these keystrokes to CTRL-TABs to move them to the next subform
instead.

'            The direction the user was trying to move can be checked by the
tab order of
'            the current field. A tab index of 0 is the first field on the
subform whilst
'            any other number is assumed to be the last field on the
subform.

' Rewrite  : Jim Dettman 10/14/94
'              Rewrote routine to make it more generic and improve
'              performance.

  Dim rstSubForm As Recordset
  Dim rstSubFormClone As Recordset
  Dim strBM As String
  Dim fAtNewRecord As Integer

  Dim fShiftDown As Integer                'Was the Shift key pressed down?
  Dim fControlDown As Integer              'Was the Ctrl key pressed down?
  Dim fAltDown As Integer                  'Was the Alt key pressed down?

  Dim fTab As Integer                      'Is the TAB key pressed?
  Dim fUp As Integer                       'Is the UP key pressed?
  Dim fDown As Integer                     'Is the DOWN key pressed?
  Dim fEnter As Integer                    'Is the ENTER key pressed?

  Dim fMovingDown As Integer               'User is trying to move down?
  Dim fMovingUp As Integer                 'User is trying to move up?

  Dim fOnFirstField As Integer             'Are we on first field or not?
  Dim fIsBound As Integer                  'Is this form bound?

  Const Routine = "SubFormNavigate"
  Const Version = "1.0.1"

  On Error GoTo SubFormNavigate_Error

' Find out the status of the SHIFT, ALT and control keys

  fShiftDown = (wShift And SHIFT_MASK) > 0
  fControlDown = (wShift And CTRL_MASK) > 0
  fAltDown = (wShift And ALT_MASK) > 0

' Find out what actual "movement" key was pressed

  fTab = (wKeyCode = KEY_TAB)
  fUp = (wKeyCode = KEY_UP)
  fDown = (wKeyCode = KEY_DOWN)
  fEnter = (wKeyCode = KEY_RETURN)

' Work out which direction the user was trying to move in.

  fMovingDown = (Not (fShiftDown) And fTab) Or fDown Or fEnter
  fMovingUp = (fShiftDown And fTab) Or fUp

' Decide if this subform is bound.

  Set rstSubForm = Frm.RecordsetClone         ' Refer to forms record set
  If IsNull(rstSubForm.Name) Then
    fIsBound = False
  Else
    fIsBound = True
  End If

' Decide if we are on first field or not.

  If strParam = "F" Then
    fOnFirstField = True
  Else
    fOnFirstField = False
  End If

' Which way are we going?

  If fOnFirstField And fMovingUp Then
        If Not (fIsBound) Then
            DoCmd.CancelEvent
            SendKeys "+^{tab}"
        Else
            On Error Resume Next
            strBM = Frm.Bookmark
            fAtNewRecord = (Err = 3021)
            On Error GoTo SubFormNavigate_Error
            If (fAtNewRecord) Then
              If (rstSubForm.RecordCount = 0) Then
                DoCmd.CancelEvent
                SendKeys "+^{tab}"
              End If
            Else
              rstSubForm.Bookmark = Frm.Bookmark
              Set rstSubFormClone = rstSubForm.Clone()
              rstSubFormClone.Bookmark = rstSubForm.Bookmark
              rstSubFormClone.MovePrevious
              If rstSubFormClone.BOF Then
                  DoCmd.CancelEvent
                  SendKeys "+^{tab}"
              End If
              rstSubFormClone.Close
            End If
        End If
    Else
        If Not (fOnFirstField) And fMovingDown Then
          If Not (fIsBound) Then
            DoCmd.CancelEvent
            SendKeys "^{tab}"
          Else
            On Error Resume Next
            strBM = Frm.Bookmark   ' Get current row bookmark
            fAtNewRecord = (Err = 3021)
            On Error GoTo SubFormNavigate_Error
            If (fAtNewRecord) Then
              DoCmd.CancelEvent
              SendKeys "^{tab}"
            Else
              ' Not at new record
              ' Need to handle case where form is read only
              ' and no new record is available
              'rstSubForm.Bookmark = frm.Bookmark
              'Set rstSubFormClone = rstSubForm.Clone()
              'rstSubFormClone.Bookmark = rstSubForm.Bookmark
              'rstSubFormClone.MoveNext
              If Frm.DefaultEditing = 3 Or Frm.DefaultEditing = 4 Then
                DoCmd.CancelEvent
                SendKeys "^{tab}"
              End If
              'rstSubFormClone.Close
            End If
          End If
        End If
    End If

Exit_SubFormNavigate:
  ' Give time for things to happen
  DoEvents

  rstSubForm.Close
  Exit Sub

SubFormNavigate_Error:
  UnexpectedError ModuleName, Routine, Version, Err, Error$
  Resume Exit_SubFormNavigate

End Sub

============================================================================
===========================================

' Purpose: Tabs user out of subform if no records exist in form
'
' Accepts: Form name and subform name
' Returns: Nothing
'
'
Sub SubFormEnter(FormName As String, SubFormControl As String)

  Dim rstSubForm As Recordset
  Dim rstSubFormClone As Recordset
  Dim fIsBound As Integer

  Const Routine = "SubFormEnter"
  Const Version = "1.0"

  On Error GoTo SubFormEnter_Error

'
' Check for empty subform. If empty, Ctrl/Tab out.
'

' Decide if this subform is bound.
  Set rstSubForm = Forms(FormName)(SubFormControl).Form.RecordsetClone
  If IsNull(rstSubForm.Name) Then
    fIsBound = False
  Else
    fIsBound = True
  End If

  If (fIsBound) And (rstSubForm.RecordCount) = 0 Then
    DoCmd.CancelEvent
    SendKeys "^{tab}"
  End If

  rstSubForm.Close

Exit_SubFormEnter:
  Exit Sub

SubFormEnter_Error:
  UnexpectedError ModuleName, Routine, Version, Err, Error$
  Resume Exit_SubFormEnter

End Sub




-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of John W. Colby
Sent: Sunday, March 07, 2004 9:32 PM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] Your favorite control behavior


>When it comes to subform tabbing you can store the tab index
(me.parent.tabindex), do a one time write of cursor navigation code for the
subform (for continuous forms for example) and at EOF, iterate the parent's
control's tab index properties and set focus to the next one so the user
doesn't know he was ever in a subform.

Sounds like one for the framework!  Thanks.

<<Snip>>
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list