Lock a tab in a tab control

  • Hi,

    I have a tab control (called tabControlRiskForm) on a form (called RiskForm) with 4 tab pages on the tab control (with a subform on each tab page). This form is opened from another form (RiskMain). On RiskMain, there are two command buttons, one for opening a selected session (selected from a list box), and one for starting a new risk session.

    What I would like is if the user clicks the new command button, then the user can only use the first tab page until the user has pressed a command button on the subform in the first tab page, and so in affect the other 3 tab pages are locked (cannot be viewed).

    I have tried putting a message box on the change event of the tab control for each page and then exiting the sub, but the tab page opens before displaying the message box.

    Private Sub tabControlRiskForm_Change()

    Select Case Me.TabControlRiskForm.value

    Case 1

    If intBrainstormID = 0 Then

    MsgBox "Please complete a risk estimate", vbOKOnly, "No estmate entered"

    Exit Sub

    End If

    End Select

    End Sub

    I also tried using the Locked event, but an error appears saying it can't be found:

    Private Sub tabControlRiskForm_Change()

    If intBrainstormID = 0 Then

    Me.TabControlRiskForm.Pages(1).Locked = True

    End If

    End Sub

    Does anyone know how to lock a tab page, or prevent a user from viewing a tab page until a requirment is met?

    Many thanks,

    Andrew

  • try Me.TabControlRiskForm.Pages(1).enabled = false

    instead of

    Me.TabControlRiskForm.Pages(1).Locked = True

  • I had tried that, in the Open event of the form as well, but it didn't work as the tab pages still opened.

    I decided to simply hide the forms on open, and then make the other tabs visible when the user clicks a certain command button in the first tab page. With only the one tab visible on open of the form, this also tells the user that this tab page must be completed before working on any of the other tab pages.

    Thanks anyway.

  • If you set the Enabled for the page to NO you could do something like this, assuming 2 pages:

    Private Sub tabControlRiskForm_Change()

    If TabControlRiskForm.Value = 1 Then 'value 1 is 2nd page index

    If Page2.Enabled = False Then

    Page1.SetFocus

    End If

    End If

    End Sub


    If you don't stand for something, you'll fall for anything!,

    Don Urquhart

  • Look at the visible property. I do this when we are doing data entry.

    Simplest thing is to open the form set the focus to a suitable control on page1 then

    page2.visible = False

    page3.visible = False

    page4.visible = False

    In the command button on page1

    page2.visible = True

    page3.visible = True

    page4.visible = True

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply