SetFocus on Tab Controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • williamson1979
    New Member
    • Feb 2019
    • 174

    #1

    SetFocus on Tab Controls

    I'm having difficulty with my tab control. A) Its difficult to switch to the correct tab by clicking it as it might take several attempts so I added
    Code:
    Private Sub tabPlantReport_Change()
    . B) When the button cmdGoToFuel is entered (Its the last tab position to send the tab control to the next page tabFuel) it goes to tabPG, however if I remove the vba for cmdGoToPG then it works.I cant seem to figure it out. C) As I stated I added
    Code:
    Private Sub tabPlantReport_Change()
    which helped clicking tabs but it also errors if I use my nav buttons, always errors on last case.

    Code:
    'Form Tab Navigation
    Private Sub tabPlantReport_Change()
      Select Case tabPlantReport
        Case 0
          cmdGotoFuel.SetFocus
        Case 1
          cmdGoToPG.SetFocus
        Case 2
          cmdGoToLime.SetFocus
        Case 3
          cmdGoToAggregate.SetFocus
      End Select
    End Sub
    Private Sub cmdGoToFuel_Enter()
    Me![tabFuel].SetFocus
    End Sub
    Private Sub cmdGoToPG_Enter()
    Me![tabPG].SetFocus
    End Sub
    Private Sub cmdGoToLime_Enter()
    Me![tabLime].SetFocus
    End Sub
    Private Sub cmdGoToAggregate_Enter()
    Me![tabAggregate].SetFocus
    End Sub
    Last edited by NeoPa; Apr 13 '19, 03:03 PM. Reason: Updated title.
  • williamson1979
    New Member
    • Feb 2019
    • 174

    #2
    I also tried this as well and removing all previous posted code:
    Code:
    Private Sub cmdGoToFuel_Enter()
      tabPlantReport.Value = (tabPlantReport.Value + 1) Mod tabPlantReport.Pages.Count
    End Sub
    Private Sub cmdGoToPG_Enter()
      tabPlantReport.Value = (tabPlantReport.Value + 1) Mod tabPlantReport.Pages.Count
    End Sub
    Once I add cmdGoToPG the same thing happens, it skips over tabFuel. I believe I must have a issue with 1 of those 2 tabs but what it could be has me lost. Any ideas?

    Comment

    • williamson1979
      New Member
      • Feb 2019
      • 174

      #3
      OK so after I figured out it was a issue with one of those tabs I looked at everything. It was definitely just that. Id added a unbound txtbox that had changed my controls tab order setting the cmdButton to go to tabPG at 0.

      With that said since Ive already posted my code which set is the best to use for navigating tabControl?

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3665

        #4
        Neither.

        If you want to go to the next page in your tab control, do this:

        Code:
        Private Sub NameOfLastControlOnPage_AfterUpdate()
            Me.NameOfNextPage.SetFocus
        End Sub
        Make things simpler, not more difficult.

        Comment

        • williamson1979
          New Member
          • Feb 2019
          • 174

          #5
          Will the afterupdate() respond when the control button has tab pressed on it?

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3665

            #6
            I have no idea what you mean by "when the control button has tab pressed on it". However, if you have a text box, which is the last text box on a page of your Tab Control and you want to move to the next page of the tab control after you have updated a value in that text box, replace NameOfLastContr olOnPage with the actual name of the control and NameOfNextPage with the actual name of the next page in the Tab Control.

            If you have a command button that moves to the next page, then just use the same .SetFocus method, but assign it to the command button's OnClick event.

            Just think about what you want to happen and when you want that to happen and work through the steps to accomplish those tasks/events.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              This has gone messy again Williamson. It starts with two questions. It's obviously going to get messy. Many experts see that and immediately decide not to waste their time on it. Please ensure only one question is asked per thread.

              Comment

              Working...