Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20

    Question Unanswered: Locking tabs connected to a Combo-Box

    This is a continuation of http://www.dbforums.com/microsoft-ac...d-records.html.

    I have been able to keep up with the new requests from the group who has asked me to do this but I have hit a brick wall on their latest.

    I have a combo box that has 4 options linked to 4 tabs:
    Cost Projection [named TabA]
    Letter Of Assignment [named TabC (yeah I know it comes second but it doesn't matter to me)]
    Exceptions [named TabB]
    Other [named TabD]

    Tab Control is named: TabCtl82

    I am now being asked to do the following: If an employee chooses one of the above, can the other tabs be locked to avoid manual manipulation? (possibly with a warning "You are not permitted to fill out more than one tab at a time. Please create another ticket for multiple situations."

    Thank you

  2. #2
    Join Date
    Oct 2006
    Posts
    110
    You could do something like

    Private Sub TabA_After Update()

    If isnull (me.TabA) = false then
    Me.tabB.enabled = false
    Me.tabC.enabled = false
    Me.TabD.enabled = false
    End If
    End Sub

    So if something is entered in the TabA field, the other fields would close.
    Are you talking about fields A-D, or tabs (pages) ?

  3. #3
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Quote Originally Posted by cmays637 View Post
    You could do something like

    Private Sub TabA_After Update()

    If isnull (me.TabA) = false then
    Me.tabB.enabled = false
    Me.tabC.enabled = false
    Me.TabD.enabled = false
    End If
    End Sub

    So if something is entered in the TabA field, the other fields would close.
    Are you talking about fields A-D, or tabs (pages) ?
    I suppose this could be one option.. but I guess I am trying to prevent them accessing the other tabs before they even type anything.

    Currently: Once a choice is made in the ComboBox the corresponding Tab is brought forth by:

    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).SetFocus
    
    End Sub
    (Thanks to Sinndho )

    I am wondering if something can be tacked onto this Private Sub?

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    blocking/disabling/errormessaging some tabs 'cos the user made a selection elsewhere seems to be against the normal tab metaphor: tabs are there to show manageable bites of stuff for the user to play with when showing all the stuff would take too much screen or be too confusing. denying some of the tabs with warning messages makes unhappy users.

    since the user will only be allowed to play with a subset of (one tabs-worth of) the fields decided by their ("elsewhere") selection - a tab control is the wrong metaphor.

    how about the user makes a selection ("elsewhere"), and then you show the user ONLY the stuff they are allowed to play with as a result of that selection: popup modal form; subform; whatever.

    there is no sense in showing the user stuff that they are not allowed to play with. users ALWAYS click where you don't want them to click ...the fix is simple: don't put it on the screen.

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Quote Originally Posted by izyrider View Post
    there is no sense in showing the user stuff that they are not allowed to play with. users ALWAYS click where you don't want them to click ...the fix is simple: don't put it on the screen.
    izy
    Everything I have put into it, including the look, has been approved by people higher than me. Changing the whole look is not an option at this point.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You could use this:

    1. When the form opens, all tabs are disabled by default and the focus is set on the ComboBox, with a message asking the user to select a tab:
    Code:
    Private Sub Form_Load()
    
        MsgBox "Please select a tab with the combo box", vbInformation, "Select Tab"
        Me.Combo_SelectTab.SetFocus
        Me.Combo_SelectTab.Dropdown
        
    End Sub
    2. You need to slightly modify the code I formerly provided, like this:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TablCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).Enabled = True
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).SetFocus
        Me.Me.Combo_SelectTab.Enabled = False
    
    End Sub
    Have a nice day!

  7. #7
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Sinndho! Thanks for helping me out

    I have tried your suggestions but it seems to be conflicting with something ( a ambiguous name detected "Form_Load"). I have another Private Sub Form_Load

    Code:
     
    Private Sub Form_Load()
    If Not Me.NewRecord Then
    RunCommand acCmdRecordsGoToNew
    End If
    End Sub

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You cannot have more than one "Form_Load" event handler in a Form class module. Gather all the lines of code from both you have into a single one then delete the other:
    Code:
    Private Sub Form_Load()
    
        If Not Me.NewRecord Then RunCommand acCmdRecordsGoToNew
        MsgBox "Please select a tab with the combo box", vbInformation, "Select Tab"
        Me.Combo_SelectTab.SetFocus
        Me.Combo_SelectTab.Dropdown
    
    End Sub
    Have a nice day!

  9. #9
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Quote Originally Posted by Sinndho View Post
    You cannot have more than one "Form_Load" event handler in a Form class module. Gather all the lines of code from both you have into a single one then delete the other:
    Code:
    Private Sub Form_Load()
    
        If Not Me.NewRecord Then RunCommand acCmdRecordsGoToNew
        MsgBox "Please select a tab with the combo box", vbInformation, "Select Tab"
        Me.Combo_SelectTab.SetFocus
        Me.Combo_SelectTab.Dropdown
    
    End Sub
    Ahh nice. That got rid of the error but it is still not locking the other tabs. What it is doing is after I choose a drop down it goes to it (like usual) then greys out the Combo-Box options. I can still click on other tabs and enter info into them.

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You need to lock them permanently by opening the form in Design view, selecting each tab and setting its "Enabled" property to "No" in the Data tab of the Properties window. Or you can programmatically disable them, in the "Form_Open" event handler for instance.
    Have a nice day!

  11. #11
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Quote Originally Posted by Sinndho View Post
    You need to lock them permanently by opening the form in Design view, selecting each tab and setting its "Enabled" property to "No" in the Data tab of the Properties window.
    That did it. You are a life saver THANK YOU!

  12. #12
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Frak I spoke too soon.

    I now get a "Run-time error '2110' : Issue Tracker can't move the focus to the control TabB when I look up or choose an older ticket.

    I hit debug and it is highlighting:

    Code:
    Private Sub Form_Current()
    
        If Not IsNull(Me.Combo_SelectTab.Value) Then
            Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).SetFocus
        End If
    
    End Sub
    Do I need to edit the code to reflect

    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).Enabled = True
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).SetFocus
        Me.Combo_SelectTab.Enabled = False
    
    End Sub
    ?

  13. #13
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    That's why you need to have:
    Code:
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).Enabled = True
    Before:
    Code:
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).SetFocus
    You cannot set the focus on a control that's disabled.
    Have a nice day!

  14. #14
    Join Date
    Nov 2011
    Location
    Queens
    Posts
    20
    Sorry I haven't been able to post, life got in the way.

    So I have tried everything and it is really causing some funky errors. If I go back to older tickets some tickets follow the rule "only allow editing in the tab chosen by the combo-box" while others allow editing in all tabs. Very odd.

    Not sure if this will help at all but I have attached a before & after of all the code I have used.
    Attached Files Attached Files

  15. #15
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can try to systematically enable/disable all tabs in the AfterUpdate event handler of the combo:
    Code:
    Private Sub Combo_SelectTab_AfterUpdate()
    
        Dim i As Long
    
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).Enabled = True
        Me.TabCtl82.Pages("Tab" & Me.Combo_SelectTab.Column(0)).SetFocus
        For i = 0 To Me.TabCtl_Steps.Pages.Count - 1
            If Me.TabCtl82.Pages(i).Name <> Me.Combo_SelectTab.Value Then
                Me.TabCtl82.Pages(i).Enabled = False
            End If
        Next i
        Me.Combo_SelectTab.Enabled = False
    
    End Sub
    This way you're sure that one and only one tab is enabled at a time.
    Have a nice day!

Posting Permissions

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