Results 1 to 7 of 7
  1. #1
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Referencing Tab Page Names instead of Index

    Good day, I have a "wizard" I have created using tab controls. The tab is named "tabWizard". It is an assortment of tabs and depending on what type of crop is chosen it will decide which pages it skips through via the "next" button. In the end, there is always a "Finish" page (index 9) that needs to change the "next" button caption to "finish".



    Code:
     If Me.tabWizard.Value = 9 Then
         Me.btnNext.Caption = "&Finish"
      Else
          Me.btnPrevious.Enabled = True
      End If
    The above code seemed the most logical choice. Unfortunately, something with my "next" button coding or just the way its made when clicking next to go to Finish page it doesn't change the tabWizard.value to 9. instead, its value is the previous page it was just on.

    I am not sure whether it's an easy fix to update its value properly or not.

    My other thought was just creating the if statement referencing the page name "Finish". But I can not find any code on google that seems to do this.

    Any help would be appreciated. Below is the full code of the "next" button onClick. Thanks!

    Code:
    Private Sub btnNext_Click()
    'Basics*
    Dim intStep As Integer
    Dim intStart As Integer
    
    Me.txtTabValue = Me.tabWizard.Value
    Me.txtCount.Value = Me.txtCount.Value + 1
    intStart = Me.txtCount.Value
    
     If Me.tabWizard.Value = Me.tabWizard.Pages.Count - 1 Then
          DoCmd.Close
          Exit Sub
       End If
       
      If Me.tabWizard.Value = 9 Then
        Me.btnNext.Caption = "&Finish"
      Else
          Me.btnPrevious.Enabled = True
      End If
      
    '/end of Basics*
    
    'Crops*
    
    'Lentils
    If CropID = 3 Then
    
    intStep = 5
        
        If Me.tabWizard.Value = 0 Then
           Me.tabWizard.Value = 1
           
        ElseIf Me.tabWizard.Value = 1 Then
            Me.tabWizard.Value = 2
            
        ElseIf Me.tabWizard.Value = 2 Then
            Me.tabWizard.Value = 3
            
        ElseIf Me.tabWizard.Value = 3 Then
            Me.tabWizard.Value = 4
            
        ElseIf Me.tabWizard.Value = 4 Then
            Me.tabWizard.Value = 9
        
        End If
        
    'Canola and Mustard
    ElseIf CropID = 1 Or 5 Then
    Dim branchloss As Integer
    
    intStep = 5
    intBranchLoss = Me.txtBranchLoss.Value
    
       
        If Me.tabWizard.Value = 0 Then
            Me.tabWizard.Value = 1
        
        ElseIf Me.tabWizard.Value = 1 Then
            Me.tabWizard.Value = 5
            
        ElseIf Me.tabWizard.Value = 5 Then
            Me.tabWizard.Value = 6
            
        ElseIf Me.tabWizard.Value = 6 Then
            Me.tabWizard.Value = intBranchLoss
            
        ElseIf Me.tabWizard.Value = intBranchLoss Then
            Me.tabWizard.Value = 9
        
        End If
       
    
    
        
    End If
    
      Me.Caption = "Count Wizard - Step " & intStart & " of " & intStep
    
    End Sub

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I'm not sure that I understand your question. Do you want to make some of the pages disabled under certain circumstances? Do you want to set the focus on a particular page after they click the Next button?

  3. #3
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    I just want to change the caption of the Next button to say Finish when its on the page named "Finish" (index value 9)

    Code:
    if me.tabwizard.pages.item = "Finish" then
    Me.btnNext.Caption = "&Finish"   Else
          Me.btnPrevious.Enabled = True
      End If
    That doesnt work. I dont know how to do the proper if statement. Its super easy using the me.tabwizard.value = 9 then.. but i cant because when switching from say page 7 to page 9 the tabwizard wont update to 9. it stays on 7. its like it doesnt update till after you hit next again.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This is how you get to the name of the page:

    Me.TabCtl0.Pages(Me.TabCtl0).Name

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I played around with your code and changed a few things.

    At the top of every module, you should have these two lines
    Code:
    Option Compare Database
    Option Explicit
    Because of the "Option Explicit" line, I found an error. Buried in the code was a declaration line
    Code:
    Dim branchloss As Integer
    But in the code you have
    Code:
    intBranchLoss = Me.txtBranchLoss.Value
    I always have any declarations at the top of the subroutine........


    I changed the IF..ELSEIF..END IF statements to SELECT CASE. Much easier to read and maintain.


    Lastly, the reason the "NEXT" button wouldn't display "Finish" is because the code to change the caption of the next button was in the wrong place.
    You have it at the top of the sub. But what is the text just above it?? Code to close the form!
    So the code to change the caption should be at the bottom of the sub.

    Once you move to the 10th tab (index 9), you should change the caption of the Next button, not the next time you click on the "Next" button.
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub btnNext_Click()
        'Basics*
        Dim intStep As Integer
        Dim intStart As Integer
        Dim intbranchloss As Integer
    
        Me.txtTabValue = Me.tabWizard
        Me.txtCount.Value = Me.txtCount + 1
        intStart = Me.txtCount.Value
    
        If Me.tabWizard = Me.tabWizard.Pages.Count - 1 Then
            DoCmd.Close
            Exit Sub
        End If
        '/end of Basics*
    
        'Crops*
        Select Case CropID
            Case 0
                'do nothing
            Case 2
                'do nothing
            Case 3    'Lentils
                intStep = 5
                Select Case Me.tabWizard
                    Case 0
                        Me.tabWizard = 1
                    Case 1
                        Me.tabWizard = 2
                    Case 2
                        Me.tabWizard = 3
                    Case 3
                        Me.tabWizard = 4
                    Case 4
                        Me.tabWizard = 9
                End Select
            Case 1, 5    'Canola and Mustard
                intStep = 5
                intbranchloss = Me.txtBranchLoss
    
                Select Case Me.tabWizard
                    Case 0
                        Me.tabWizard = 1
                    Case 1
                        Me.tabWizard = 5
                    Case 5
                        Me.tabWizard = 6
                    Case 6
                        Me.tabWizard = intbranchloss
                    Case intbranchloss
                        Me.tabWizard = 9
                End Select
            
            Case Else
    
        End Select
    
        If Me.tabWizard = 9 Then
            Me.btnNext.Caption = "&Finish"
        Else
            Me.btnPrevious.Enabled = True
        End If
    
        Me.Caption = "Count Wizard - Step " & intStart & " of " & intStep
    
    End Sub

  6. #6
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Thank you very much, that code worked perfectly. Appreciate the time you put into it!

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Excellent! Glad it worked for you...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 10-30-2016, 05:39 AM
  2. Replies: 3
    Last Post: 10-30-2014, 03:34 PM
  3. Referencing Field Names
    By andy-29 in forum Access
    Replies: 6
    Last Post: 11-20-2012, 03:27 PM
  4. Can you place Multiple Field Names to a Single Index?
    By VanillaAwesome in forum Access
    Replies: 2
    Last Post: 08-05-2012, 04:40 PM
  5. Replies: 5
    Last Post: 04-24-2011, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums