Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20

    Unanswered: Linking combo-box to a tab

    Hello everyone!

    New guy asking a question i couldn't find in the search feature (apologies ahead of time if it was asked before.)

    I have a form which has a combo-box with 4 answers: AnswerA, AnswerB, AnswerC & AnswerD.

    I also have 4 tabs on it: TabA, TabB, TabC & TabD

    Is there a way to link the 2 together? If I choose AnswerB in the combo I would like to force Access to show TabB (don't really care if the inputter still has access to the other tabs)

    Appreciate any ideas
    [using Access 2003]

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Let's suppose that the combo has its bound column containing the numbers 0, 1, 2, 3 (this column can be invisible). You can use:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages(Me.Combo_SelectTab.Value).SetFocus
        
    End Sub
    If you insist on working with the names instead of the numerical index, and if the bound column of the combo contains the values "AnswerA", "AnswerB", "AnswerC", "AnswerD", you can use:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Tab" & Right(Me.Combo_SelectTab.Value, 1)).SetFocus
        
    End Sub
    If the column of the combo you need to use is not the bound column, you can retrieve the value from another column of the combo using:
    Code:
    Me.Combo_SelectTab.Column(n)
    where n = 0 for the first (leftmost) column, 1 for the second, etc. The same principle is true for the tabs of a tabcontrol: the first (leftmost) tab is Tab(0), the second is Tab(1), etc.
    Have a nice day!

  3. #3
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Wow thanks for the fast response!!!

    I just got home so I'll take a look at work tomorrow and let you know how it turns out.

  4. #4
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Quote Originally Posted by Sinndho View Post
    Let's suppose that the combo has its bound column containing the numbers 0, 1, 2, 3 (this column can be invisible). You can use:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages(Me.Combo_SelectTab.Value).SetFocus
        
    End Sub
    If you insist on working with the names instead of the numerical index, and if the bound column of the combo contains the values "AnswerA", "AnswerB", "AnswerC", "AnswerD", you can use:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Tab" & Right(Me.Combo_SelectTab.Value, 1)).SetFocus
        
    End Sub
    If the column of the combo you need to use is not the bound column, you can retrieve the value from another column of the combo using:
    Code:
    Me.Combo_SelectTab.Column(n)
    where n = 0 for the first (leftmost) column, 1 for the second, etc. The same principle is true for the tabs of a tabcontrol: the first (leftmost) tab is Tab(0), the second is Tab(1), etc.
    My combo-box is linked to a Table which has only one column called "Category." I admit I had to look up what a BoundColumn was and I assume that it is.

    Regarding the Code, I have tried a few variations but nothing working as of yet. Please bear with me as I haven't done much of this. I tried as an event in the Combo Boxes "AfterUpdate":

    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Answer A" & Right(Me.Combo_SelectTab.Value, 0)).SetFocus
        Me.TabCtl0.Pages("Answer B" & Right(Me.Combo_SelectTab.Value, 1)).SetFocus
        Me.TabCtl0.Pages("Answer C" & Right(Me.Combo_SelectTab.Value, 2)).SetFocus
        Me.TabCtl0.Pages("Answer D" & Right(Me.Combo_SelectTab.Value, 3)).SetFocus    
    
    
    End Sub
    And
    Code:
    Me.TabCtl0.Pages("[Answer A]" & Right(Me.Combo_SelectTab.Value, 0)).SetFocus

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    In your first post you said:
    Quote Originally Posted by Claymoore View Post
    I have ... a combo-box with 4 answers: AnswerA, AnswerB, AnswerC & AnswerD.

    I also have 4 tabs on it: TabA, TabB, TabC & TabD
    1. For changing the active tab of the TabControl we use:
    Code:
    Me.<TabControlName>.Pages("<TabName>").SetFocus
    Where "<TabControlName>" is the name of the TabControl and "<TabName>" is the name of the tab we want to select.


    2. The result of the expression we need to use then is something like (here for selecting "TabB" from a TabControl named "TabCtl0"):
    Code:
    Me.TabCtl0.Pages("TabB").SetFocus

    3. The common feature that relates each possible value of the ComboBox ("AnswerA", "AnswerB", "AnswerC" and "AnswerD") and the name of each Tab ("TabA", "TabB", "TabC" and "TabD") is the last letter which is the same for both ("A", "B", "C" and "D").


    4. We must then build the name of the Tab we want to select by adding the last letter of the value in the ComboBox to the common part in the name of each Tab: "Tab"


    5. The VBA function that returns the last letter of a string expression or value is: Right(Value, CharacterCount). So, to extract the last letter from the value in the ComboBox, we use the expression (if the name of the ComboBox is "Combo_SelectTab"):
    Code:
    Right(Me.Combo_SelectTab.Value, 1)
    Which (from 3. hereabove) will return "A", "B", "C", or "D".


    6. From 4. hereabove, the returned letter must be added to the litteral string "Tab" which is the beginning of the name of each Tab in the TabControl. So the name of the desired Tab can be obtained from this expression:
    Code:
    "Tab" & Right(Me.Combo_SelectTab.Value, 1)

    7. From 1. and 2. hereabove, we can then write (again for a TabControl named "TabCtl0" and a ComboBox named "Combo_SelectTab"):
    Code:
    Me.TabCtl0.Pages("Tab" & Right(Me.Combo_SelectTab.Value, 1)).SetFocus

    8. As the Tab must change when the value of the ComboBox changes, we shall use this statement in response to the AfterUpdate event for the ComboBox, as this event occurs immediately after the selected item in the ComboBox (which is represented by its Value property) is being changed:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Tab" & Right(Me.Combo_SelectTab.Value, 1)).SetFocus
        
    End Sub
    Have a nice day!

  6. #6
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    I think I am getting the hang of this. Appreciate your patience!

    Changed the name of the Combo-box to your "Combo_SelectTab" just to make it easier...


    Getting an error though when I chose from the Combo-Box

    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Tab" & Right(Me.Combo_SelectTab.Value, 1)).SetFocus
        
    End Sub
    Compile error:
    Method or data member not found.

    Does each tab have it's own "TabCtl"? If so where would I find the name?

    Thanks

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    What's the actual name of the TabControl in your form, what are the actual names of the pages (tabs) is this TabControl, and what are the actual values contained in the ComboBox?
    Have a nice day!

  8. #8
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Quote Originally Posted by Sinndho View Post
    What's the actual name of the TabControl in your form, what are the actual names of the pages (tabs) is this TabControl, and what are the actual values contained in the ComboBox?
    Actual names of the Tabs (which I changed to make it easier): TabA TabB TabC TabD

    Now for the Combo-box, I had to change the one column to a two column. I followed the instructions here: MS Access: Bind combo box to primary key but display a description field in Access 2003/XP/2000/97

    Value Category
    A Cost Projection
    B Exceptions
    C Letter Of Assignment
    D Other

  9. #9
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Then you can skip using the Right() function and use:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Tab" & Me.Combo_SelectTab.Value).SetFocus
        
    End Sub
    If the name of the TabControl is not "TabCtl0", change the statement accordingly.
    Have a nice day!

  10. #10
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20

    Thumbs up

    Quote Originally Posted by Sinndho View Post
    Then you can skip using the Right() function and use:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl0.Pages("Tab" & Me.Combo_SelectTab.Value).SetFocus
        
    End Sub
    If the name of the TabControl is not "TabCtl0", change the statement accordingly.
    Sorry for the confusion but I finally figured out what the TabCtl was on my form. It was right in front of my face.. ugg.

    I really appreciate all your help - it is working perfectly.

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

  12. #12
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20

    Follow up question...

    posting in a new thread.
    Last edited by Claymoore; 11-12-11 at 13:59. Reason: posting a new 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
  •