Can certain tabs in a tab control show/hide based on a field in a form?

gojets1721

Registered User.
Local time
Yesterday, 22:15
Joined
Jun 11, 2019
Messages
430
I've got this form full of complaints that shows each complaint entry one at a time. The form has a tab control and there's a bunch of tabs to store extra info. But a lot of the tabs are specific to certain types of complaints. So if its a billing compliant, there's a certain tab that has all these billing-specific fields. But if it isn't billing related, that tab is shown regardless and it's basically useless.

My question is, is there a way for tabs to show/hide based on what is listed in the category field? The category field is completely standardized and there's 4 categories

Thanks!
 
You can use something like:
Code:
Me.TabControlName.Pages(PageIndex).Visible=False
Hope that helps...
 
The example "Password Protected Tab" on the nifty Access website here may be useful to you:-

 
You can use something like:
Code:
Me.TabControlName.Pages(PageIndex).Visible=False
Hope that helps...
Hi DB...admittedly I'm not really sure where to place that code or how to input my info. The billing tab is just called 'Billing'. The category is also 'billing'.
 
Hi DB...admittedly I'm not really sure where to place that code or how to input my info. The billing tab is just called 'Billing'. The category is also 'billing'.
Can you post a demo version of your db? We can't tell you where to put the code either if we have no idea what your form looks like.
 
Can you post a demo version of your db? We can't tell you where to put the code either if we have no idea what your form looks like.
Fair point. Sorry. See attached. Very raw example but hopefully it works. Each category tab has more category-specific data based on what type of complaint it is. If the entry is a billing complaint, I'd like for the other category tabs to disappear
 

Attachments

See if this does what you want. Open the form and cycle through the records.

PS. I only modified the Current event. You'll have to use other events based on what you really need.
 

Attachments

Code:
Private Sub ComplaintType_AfterUpdate()
  ShowTabs
End Sub

Private Sub Form_Current()
  ShowTabs
End Sub

Public Sub ShowTabs()
  Dim pg As Page
  'send focus to correct tab
  Me.ComplaintType.SetFocus
  For Each pg In Me.TabCtl22.Pages
     pg.Visible = (pg.Name = Nz(Me.ComplaintType))
  Next pg
End Sub
 
See if this does what you want. Open the form and cycle through the records.

PS. I only modified the Current event. You'll have to use other events based on what you really need.
Hi DB. This is exactly what I'm looking for. Do you mind briefly explaining how you got this to work? That way I can replicate it in my actual DB
 
Hi DB. This is exactly what I'm looking for. Do you mind briefly explaining how you got this to work? That way I can replicate it in my actual DB
Hi. It's basically the same logic as what @MajP posted, except I assumed you always wanted the Overview tab displayed for all categories. If you go through the code, let us know if you don't understand any of them.
 
Last edited:
Let's say in my actual database, I want the first two tabs to always remain. Would the alteration in the code be:

Code:
For x = 2 To Me.TabCtl22.Pages.Count - 2
 
Using @theDBguy assumption about the Overview
Code:
Public Sub ShowTabs()
  Dim pg As Page
  'send focus away from tab
  Me.ComplaintType.SetFocus
  For Each pg In Me.TabCtl22.Pages
     pg.Visible = (pg.Name = Nz(Me.ComplaintType) Or pg.Name = "Overview" or pg.name = "Some Other Name")
  Next pg
End Sub

You can add ORs to the check
 
Let's say in my actual database, I want the first two tabs to always remain. Would the alteration in the code be:

Code:
For x = 2 To Me.TabCtl22.Pages.Count - 2
No, it would be more like:
Code:
For x = 2 To Me.TabCtl22.Pages.Count - 1
 

Users who are viewing this thread

Back
Top Bottom