• ‘Tab’ to next Tab Control Page (2000/XP)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » ‘Tab’ to next Tab Control Page (2000/XP)

    Author
    Topic
    #403316

    Is there a clever way to move to the first control on the following tab control page as you leave (tab out) of the last control and the a page (not a great sentence but it should make sense).

    I’m using the lost focus event of the appropriate control to set the focus of the next control. just wondered if the was a more general way of doing this without having to hard code control names etc.

    Viewing 3 reply threads
    Author
    Replies
    • #810528

      You can use Ctrl + Tab to move to the next tab (page). I tried this technique on one of my tabbed forms, and it appears to work no matter where the focus is at the moment.

      • #810559

        I was thinking about code but that’ll do just fine – I never knew you could do that, cheers.

        • #810569

          You could create a little procedure like this

          Private Sub sbnextpage()
          Me!TabPage = Me!TabPage + 1
          End Sub

          and then in the onlost focus event for the last control on each page (except the last one) just put:

          sbnextpage

          You need to replace tabpage with the name of your tabbed form

          • #810696

            I would generalize this somewhat to handle case where current tab (page) is last page on tab control:

            Private Sub GoToNextTab()

            With Me.TabCtl1
            If .Value = .Pages.Count – 1 Then
            .Value = 0
            Else
            .Value = .Value + 1
            End If
            End With

            End Sub

            This sub is somewhat generic, only thing you would need to change would be control name. You’d have to modify this only if the tab control has some hidden pages.

            HTH

            • #811206

              Thanks, both of you. I’ve used Marks idea which does all I need.

              I need to do a similar thing after a combo box is updated, but just move to the next control in the tab index.

              I guess it must be something similar with a “something + 1 “in there but I can’t think what to reference. I’ve been searching the forum but haven’t found anything yet.

            • #811218

              Do you mean that you want the focus to shift to the next control as soon as the user selects an item in the combo box, without pressing Tab? I think that would be irritating – users often don’t select the correct item the first time; if they try to correct it, they find that the focus has already shifted away from the combo box, so they have to go back first…

            • #811230

              That is what I meant and I agree it annoying.

              I’ve been trying unsuccessfully to add a get out clause if the user picks the value “None” from a combo box. There are about 6 other combos dependent on this one (this is discussed in my other thread). If the combo is set to “None” the other must be set to “N/A”, I am checking to see if these other combos have values and if they do, then warn the user with a message box that if thet continue they will loose data that may be important.

              The trouble is I can’t cancel the change to the main combo

              Neither of these work

              Cancel = true
              DcCmd.CancelEvent

              SendKeys “{ESC}” is a little erratic, as it resets all uncommited values, not just the one in one of these main combos.

              and I am sceptical about using Value and OldValue

              I was trying to pass to Text in the combo box to a variable which could be used to reset the value. The only way I could do this successfully was via the On Enter event. I think I wanted the focus to leave the combo to make sure this varaible was kept up to date.

              I may just give up with this and make the form behave the way it did when I inherited it, which to reset things without any warning

            • #811235

              You can use the Undo method of the combo box to restore the previous value, see post 361118

            • #811243

              Sorry, my brain is cooked cooked

              So Cancel=True isn’t supposed to actually reset a combo value?

            • #811265

              No, Cancel = True just means that the stored value is not updated, and that the focus won’t move away from the combo box. The text in the text box portion of the combo box will not be reset, however. That is what the Undo method is for.

            • #811266

              No, Cancel = True just means that the stored value is not updated, and that the focus won’t move away from the combo box. The text in the text box portion of the combo box will not be reset, however. That is what the Undo method is for.

            • #811244

              Sorry, my brain is cooked cooked

              So Cancel=True isn’t supposed to actually reset a combo value?

            • #811236

              You can use the Undo method of the combo box to restore the previous value, see post 361118

            • #811231

              That is what I meant and I agree it annoying.

              I’ve been trying unsuccessfully to add a get out clause if the user picks the value “None” from a combo box. There are about 6 other combos dependent on this one (this is discussed in my other thread). If the combo is set to “None” the other must be set to “N/A”, I am checking to see if these other combos have values and if they do, then warn the user with a message box that if thet continue they will loose data that may be important.

              The trouble is I can’t cancel the change to the main combo

              Neither of these work

              Cancel = true
              DcCmd.CancelEvent

              SendKeys “{ESC}” is a little erratic, as it resets all uncommited values, not just the one in one of these main combos.

              and I am sceptical about using Value and OldValue

              I was trying to pass to Text in the combo box to a variable which could be used to reset the value. The only way I could do this successfully was via the On Enter event. I think I wanted the focus to leave the combo to make sure this varaible was kept up to date.

              I may just give up with this and make the form behave the way it did when I inherited it, which to reset things without any warning

            • #811219

              Do you mean that you want the focus to shift to the next control as soon as the user selects an item in the combo box, without pressing Tab? I think that would be irritating – users often don’t select the correct item the first time; if they try to correct it, they find that the focus has already shifted away from the combo box, so they have to go back first…

            • #811207

              Thanks, both of you. I’ve used Marks idea which does all I need.

              I need to do a similar thing after a combo box is updated, but just move to the next control in the tab index.

              I guess it must be something similar with a “something + 1 “in there but I can’t think what to reference. I’ve been searching the forum but haven’t found anything yet.

          • #810697

            I would generalize this somewhat to handle case where current tab (page) is last page on tab control:

            Private Sub GoToNextTab()

            With Me.TabCtl1
            If .Value = .Pages.Count – 1 Then
            .Value = 0
            Else
            .Value = .Value + 1
            End If
            End With

            End Sub

            This sub is somewhat generic, only thing you would need to change would be control name. You’d have to modify this only if the tab control has some hidden pages.

            HTH

        • #810570

          You could create a little procedure like this

          Private Sub sbnextpage()
          Me!TabPage = Me!TabPage + 1
          End Sub

          and then in the onlost focus event for the last control on each page (except the last one) just put:

          sbnextpage

          You need to replace tabpage with the name of your tabbed form

      • #810560

        I was thinking about code but that’ll do just fine – I never knew you could do that, cheers.

    • #810529

      You can use Ctrl + Tab to move to the next tab (page). I tried this technique on one of my tabbed forms, and it appears to work no matter where the focus is at the moment.

    • #812382

      Besides the other ideas you’ve been given about moving from tab to tab in a form, you can also move to a specific tab by referring to it by name, for example: “TabCtl0.Pages(“FinalTab”).SetFocus.” In this instance, the name of my final tab is, “FinalTab” .
      thx
      Pat

      • #812408

        I often use Tab Controls with hidden pages that are visible based on dynamic conditions such security settings (ie, “Admin Only” tabs, etc) so was looking for good way to navigate between tabs w/o having to “hard code” for possibly hidden tab pages. The only reliable way I found to do this was to populate an array when form opens (or whenever else the Visible property of any of the tab pages changes) to keep track of which pages are visible and can be navigated to w/o error. Sample code used:

        Option Explicit

        Dim VisIndex() As Integer
        Dim VisIndexMin As Variant
        Dim VisIndexMax As Variant

        Private Sub GetVisIndex()

        Dim intPageCount As Integer
        Dim n As Integer ‘ Loop counter
        Dim i As Integer ‘ Visible page counter

        If Not IsEmpty(VisIndex) Then
        Erase VisIndex ‘ re-initialize array
        End If

        With Me.TABCTL1
        intPageCount = .Pages.Count
        ReDim VisIndex(intPageCount – 1)
        For n = 0 To intPageCount – 1
        If .Pages(n).Visible = True Then
        VisIndex(i) = n
        i = i + 1
        End If
        Next n
        If i > 0 Then
        ReDim Preserve VisIndex(i – 1)
        VisIndexMin = VisIndex(0)
        VisIndexMax = VisIndex(i – 1)
        Else
        VisIndexMin = Null
        VisIndexMax = Null
        End If
        End With

        End Sub

        This populates several module-level variables, including an array. Sub used to navigate to next or previous (visible) tab page:

        Private Sub GoToNextTab(ByRef Direction As Integer)
        On Error GoTo Err_Handler

        Dim strMsg As String
        Dim n As Integer ‘ Loop counter
        ‘ Direction: 1 = Next, -1 = Previous

        With Me.TABCTL1
        If Not IsNull(VisIndexMin) Then
        If .Value = VisIndexMax And Direction = 1 Then
        .Value = VisIndexMin
        ElseIf .Value = VisIndexMin And Direction = -1 Then
        .Value = VisIndexMax
        Else
        For n = 0 To UBound(VisIndex)
        If VisIndex(n) = .Value Then
        .Value = VisIndex(n + Direction)
        Exit For
        End If
        Next n
        End If
        Else
        ‘ No visible pages found:
        strMsg = “No tab pages are visible. Action cancelled.”
        MsgBox strMsg, vbExclamation, “ACTION CANCELLED”
        End If
        End With

        Exit_Sub:
        Exit Sub
        Err_Handler:
        strMsg = “Error No ” & Err.Number & “: ” & Err.Description
        MsgBox strMsg, vbExclamation, “GO TO NEXT TAB ERROR MESSAGE”
        Resume Exit_Sub
        End Sub

        The attached file is a small demo db (A2K format) that demonstrates this technique. The form (frmTabControl) has a tab control with 8 pages. There are 4 command buttons, similar to record navigation buttons, used to navigate to first, previous, next, or last visible tab page (if on last tab, “Next” button will move to first; if on first tab, “Previous” will move to last tab). To test this, there are 8 checkboxes to toggle the Visible property of the tab pages on or off (there are also buttons to toggle the tab control’s MultiRow and Tab Style properties). The tab navigation buttons function correctly, no matter how many tab pages are hidden – even if all 8 are hidden (which wouldn’t make a lot of sense in actual practice). If you don’t have to deal with hidden tab pages the (much simpler) code previously posted should suffice. See attached demo for more details.

        HTH

        • #812678

          Thank you! Simple, but exquisite! Your solution and others are more what Darsha was looking for — I just wanted to show an alternative, albeit more plodding, way of referring to that tab. Your sample w/ the variably-displayed tabs is quite a bit nicer looking than the enabling / disenabling tabs that I have done in the past. I had fun with your tab form .
          Pat

        • #812679

          Thank you! Simple, but exquisite! Your solution and others are more what Darsha was looking for — I just wanted to show an alternative, albeit more plodding, way of referring to that tab. Your sample w/ the variably-displayed tabs is quite a bit nicer looking than the enabling / disenabling tabs that I have done in the past. I had fun with your tab form .
          Pat

      • #812409

        I often use Tab Controls with hidden pages that are visible based on dynamic conditions such security settings (ie, “Admin Only” tabs, etc) so was looking for good way to navigate between tabs w/o having to “hard code” for possibly hidden tab pages. The only reliable way I found to do this was to populate an array when form opens (or whenever else the Visible property of any of the tab pages changes) to keep track of which pages are visible and can be navigated to w/o error. Sample code used:

        Option Explicit

        Dim VisIndex() As Integer
        Dim VisIndexMin As Variant
        Dim VisIndexMax As Variant

        Private Sub GetVisIndex()

        Dim intPageCount As Integer
        Dim n As Integer ‘ Loop counter
        Dim i As Integer ‘ Visible page counter

        If Not IsEmpty(VisIndex) Then
        Erase VisIndex ‘ re-initialize array
        End If

        With Me.TABCTL1
        intPageCount = .Pages.Count
        ReDim VisIndex(intPageCount – 1)
        For n = 0 To intPageCount – 1
        If .Pages(n).Visible = True Then
        VisIndex(i) = n
        i = i + 1
        End If
        Next n
        If i > 0 Then
        ReDim Preserve VisIndex(i – 1)
        VisIndexMin = VisIndex(0)
        VisIndexMax = VisIndex(i – 1)
        Else
        VisIndexMin = Null
        VisIndexMax = Null
        End If
        End With

        End Sub

        This populates several module-level variables, including an array. Sub used to navigate to next or previous (visible) tab page:

        Private Sub GoToNextTab(ByRef Direction As Integer)
        On Error GoTo Err_Handler

        Dim strMsg As String
        Dim n As Integer ‘ Loop counter
        ‘ Direction: 1 = Next, -1 = Previous

        With Me.TABCTL1
        If Not IsNull(VisIndexMin) Then
        If .Value = VisIndexMax And Direction = 1 Then
        .Value = VisIndexMin
        ElseIf .Value = VisIndexMin And Direction = -1 Then
        .Value = VisIndexMax
        Else
        For n = 0 To UBound(VisIndex)
        If VisIndex(n) = .Value Then
        .Value = VisIndex(n + Direction)
        Exit For
        End If
        Next n
        End If
        Else
        ‘ No visible pages found:
        strMsg = “No tab pages are visible. Action cancelled.”
        MsgBox strMsg, vbExclamation, “ACTION CANCELLED”
        End If
        End With

        Exit_Sub:
        Exit Sub
        Err_Handler:
        strMsg = “Error No ” & Err.Number & “: ” & Err.Description
        MsgBox strMsg, vbExclamation, “GO TO NEXT TAB ERROR MESSAGE”
        Resume Exit_Sub
        End Sub

        The attached file is a small demo db (A2K format) that demonstrates this technique. The form (frmTabControl) has a tab control with 8 pages. There are 4 command buttons, similar to record navigation buttons, used to navigate to first, previous, next, or last visible tab page (if on last tab, “Next” button will move to first; if on first tab, “Previous” will move to last tab). To test this, there are 8 checkboxes to toggle the Visible property of the tab pages on or off (there are also buttons to toggle the tab control’s MultiRow and Tab Style properties). The tab navigation buttons function correctly, no matter how many tab pages are hidden – even if all 8 are hidden (which wouldn’t make a lot of sense in actual practice). If you don’t have to deal with hidden tab pages the (much simpler) code previously posted should suffice. See attached demo for more details.

        HTH

    • #812383

      Besides the other ideas you’ve been given about moving from tab to tab in a form, you can also move to a specific tab by referring to it by name, for example: “TabCtl0.Pages(“FinalTab”).SetFocus.” In this instance, the name of my final tab is, “FinalTab” .
      thx
      Pat

    Viewing 3 reply threads
    Reply To: ‘Tab’ to next Tab Control Page (2000/XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: