Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    64

    Unanswered: Set tab order to new page on same form

    I have a form with several subforms, each on a different tab page. I have the name of a patient at the top and then the tabbed pages with different information like procedures, contact, Etc.. that are all a subform. how do I set the tab order to go to the first item in the next page when you tab out of the last item on that page?

  2. #2
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    There may be better ways but you can do it with a couple lines of code.

    Just set the following events on the last field on your form.

    Code:
    Dim key As Integer
    
    Private Sub LastField_Enter()
        If (key <> Null) Then key = Null
    End Sub
    
    Private Sub LastField_Exit(Cancel As Integer)
        If (key = 9) Then
            Forms![ParentForm]![NextForm].SetFocus
        End If
    End Sub
    
    Private Sub LastField_KeyDown(KeyCode As Integer, Shift As Integer)
        key = KeyCode
    End Sub
    If you leave by clicking somewhere else then nothing will happen, but if you are tabbing thru the fields the if statement in the exit event will execute and move you to the next form

    Steve

  3. #3
    Join Date
    May 2012
    Posts
    64
    It doesn't seem to be working! I clicked on the last form field on that page and clicked view code and pasted that in. Do I need to change any of the text in the code?

  4. #4
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Yes, you would have to update the names. Without knowing your form layout I was only able to guess what you called things.

    In my example LastField is the name of the last text box on the first subform tab (where you want the action to start). Change this portion in all three events so the form code can find them.

    You would also have to change ParentForm & NextForm insides the brackets of
    Forms![ParentForm]![NextForm].SetFocus to match the name of your forms. ParentForm is the one that contains both of your forms, NextForm is the one you want to go to on the next tab.

    Hope this helps.

    Steve

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •