Results 1 to 14 of 14
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'Tab' to next Tab Control Page (2000/XP)

    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.

  2. #2
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

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

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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
    Regards
    John



  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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...

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    You can use the Undo method of the combo box to restore the previous value, see <post#=361118>post 361118</post#>

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    Sorry, my brain is cooked <img src=/S/cooked.gif border=0 alt=cooked width=50 height=46>

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

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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.

  12. #12
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Salem, Oregon, USA
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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" <g>.
    thx
    Pat

  13. #13
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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
    Attached Files Attached Files

  14. #14
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Salem, Oregon, USA
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Tab' to next Tab Control Page (2000/XP)

    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 <g>.
    Pat

Posting Permissions

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