none
I can't tab out of my tab control! RRS feed

  • Question

  • I have a form that contains a tab control, with three (soon-to-be-four) tab pages.  Each tab page contains a subform.  When I tab through the form entering information, everything works fine.  All of the data is present in the underlying tables.  no issues there.  But when I've entered all the information in a given tab page, and I attempt to tab back to the containing form and on to the next record, the cursor instead cycles indefinitely on the present tab page and goes nowhere.

    Cycle Property set to 'All Records' has no effect on the page's subform.  That's why I'm here.

    Expected / Intended behavior: Tab to each field, fill in necessary information. Tab to tab control, tab through subform fields on tab page 1 filling necessary information, then jump back to the containing form and the next record in sequence.

    What is actually happening:  Tab to each field, fill in necessary information, Tab to tab control,  tab through subform fields on tab page 1 filling information, continuous cycle on the empty row - does not leave the subform, the tab page, the tab control.

    USING MS Access 2010. Am I missing something very simple, or is there a way programmatically to accomplish the above task? like, if 'current-record' is empty then navigate to 'next-control-in-containing-form'?  HELP!

    Saturday, March 29, 2014 3:24 PM

Answers

  • A simple solution is to use Ctrl+Tab to move from the subform to the next control on the main form.

    Alternatively, you can use some VBA code for this purpose. Let's say that the (control bound to the) primary key of the record source of the subform is named RecordID, that the last control in the tab order of the subform is named LastControl, and that you want to set focus to a control on the main form named MainControl

    Create an On Key Down event procedure for LastControl:

    Private Sub LastControl_KeyDown(KeyCode As Integer, Shift As Integer)
        ' Are we in an empty new record and did the user press Tab?
        If IsNull(Me.RecordID) And KeyCode = vbKeyTab Then
            ' Set focus to a control on the main form
            Me.Parent!MainControl.SetFocus
            ' Cancel the keystroke
            KeyCode = 0
        End If
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by mozzie0331 Sunday, March 30, 2014 5:12 PM
    Saturday, March 29, 2014 4:12 PM

All replies

  • A simple solution is to use Ctrl+Tab to move from the subform to the next control on the main form.

    Alternatively, you can use some VBA code for this purpose. Let's say that the (control bound to the) primary key of the record source of the subform is named RecordID, that the last control in the tab order of the subform is named LastControl, and that you want to set focus to a control on the main form named MainControl

    Create an On Key Down event procedure for LastControl:

    Private Sub LastControl_KeyDown(KeyCode As Integer, Shift As Integer)
        ' Are we in an empty new record and did the user press Tab?
        If IsNull(Me.RecordID) And KeyCode = vbKeyTab Then
            ' Set focus to a control on the main form
            Me.Parent!MainControl.SetFocus
            ' Cancel the keystroke
            KeyCode = 0
        End If
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by mozzie0331 Sunday, March 30, 2014 5:12 PM
    Saturday, March 29, 2014 4:12 PM
  • I was hitherto unaware of the ctrl+tab option, which works wonderfully.

    I'm getting pretty handy with VBA, but this is definitely a reminder (to me, anyway), that there's still much for me to learn - I didn't know there was a LastControl event!  Thank you, Mr. Vogelaar!

    Sunday, March 30, 2014 9:48 PM
  • Please note that LastControl is not a built-in feature. I used this name as an example:

    "Let's say that (...) the last control in the tab order of the subform is named LastControl"

    You should replace LastControl with the name that you gave the last control in the tab order of the subform.

    On KeyDown is a built in event of text boxes and other controls; this event lets you decide what happens when the user presses a key. See the Access VBA help: http://msdn.microsoft.com/en-us/library/office/ff844722(v=office.14).aspx


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, March 31, 2014 3:04 AM
  • Hey Hans!

    I came up with an easier code that simulates pressing Ctrl+Tab instead.

    Private Sub LastControlField_LostFocus()
    
    If IsNull(Me.RecordIDField) Then
    
      SendKeys ("^{TAB}")
      ' ^ is the Ctrl modifier
    
    End If
    
    End Sub

    Wednesday, April 30, 2014 2:37 AM