Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable a tab in a tabcontrol 1

Status
Not open for further replies.

dkaplan

Programmer
Jan 29, 2001
98
US
I am trying to disable a scpecific tab in a tabcontrol depending on how a checkbox is populated in a subforrm.

I tried using:

me.tabName.enabled = false but this is ignored.

me.tabName.Visible = false DOES work. But my preferred behavior would be for the tab to remain visible but inactive with the caption grayed out.
 
How are ya dkaplan . . .

Try:
Code:
[blue]Me![purple][B][I]TabControlName[/I][/B][/purple].Pages("[purple][B][I]PageName[/I][/B][/purple]").Enabled = False[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks Ace1,

I tried this, but I'm afraid it still ignores me.

As before, it does work with visible, i.e.

Me!TabControlName.Pages("tabName").visible = False

Could it be that Access doesn't permit dynamically disabling a single tab?
 
dkaplan . . .

In 2003, if I select the page I disabled I find all the controls on the page are just that ... [blue]disabled![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Correct, TheAceMan1. I probably should have been more explicit.

There are currently no controls on my tab. Selecting it does something else in the app (I'll spare you the details).

The behavior I was looking for was to leave the tab visible, but to gray out the caption and suppress the click events.

It's looking to me like Access interprets enabled = false, exactly as you have stated (tab still visible but controls disabled.)

Thanks for your insights though. Fortunately, I can still get by using visible instead of enabled.

dkaplan
 
If I understand you correctly you could simulate it. Greying out the caption is not easy but you could change it. Then when you click on the tab it would appear as if nothing happens.

This demo makes it appear as if the tab is locked.
Code:
Public blnLocked As Boolean
Public oldPageIndex As Integer
Public oldPageCaption As String
Private Sub Command5_Click()
  blnLocked = Not blnLocked
  If blnLocked Then
    Me.TabCtl0.Pages(2).Caption = oldPageCaption & "(Disabled)"
  Else
    Me.TabCtl0.Pages(2).Caption = oldPageCaption
  End If
    
End Sub
Private Sub Form_Load()
  oldPageCaption = Me.TabCtl0.Pages(2).Caption
End Sub

Private Sub TabCtl0_Change()
    If Me.TabCtl0.Value <> 2 Then
       oldPageIndex = Me.TabCtl0.Value
     ElseIf blnLocked Then
       Me.TabCtl0.Value = oldPageIndex
     End If
End Sub
 
Thanks, Majp.

This looks like an excellent workaround.

DKaplan
 
There is a better work around if you really want to do this. The tab control has a style property: tabs, buttons, none. If you pick "none" you can make a tab control with no tabs. Then above the tab control you fake the tabs with labels. With a little formatting you can make it look just like tabs but you can do things like change the color of the label. When you click a label you can change the value of the tab control to the associated page. You can also play with the special effect of the label to make the clicked label "raised" and the remaining labels sunken. Now you can completely fake "greying out".
 
if you do a little googling you will see this technique used to give each "tab" a different color or to change the color of the selected "tab".
 
Thanks, MajP.

This has been very helpful.

dkaplan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top