Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Trying to hide tabs on a form

I have four tabs on a tabbed form and if certain criteria exists I want to hide two of them.  My code isn't working and I wonder if the names of the tabs are causing the problem.  They are actually named:

Consumables - Toner
and
Rates - Toner


but as you can see, Access is changing the names of the controls...


Here is my oncurrent event code:

    If Me.cboPrintProcess = "Inkjet" Then
        Me.Consumables___Toner.Visible = False
        Me.Rates___Toner.Visible = False
        Else
        Me.Consumables___Toner.Visible = True
        Me.Rates___Toner.Visible = True
    End If
0
SteveL13
Asked:
SteveL13
  • 5
  • 4
  • 2
  • +1
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Try this:

Me.Controls("Consumables - Toner").Visible = False
Me.Controls("Rates - Toner").Visible = False
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Does your code actually make it to where you set the values? Set a Breakpoint on this line:

If Me.cboPrintProcess = "Inkjet" Then

And run the code again. What's the value of "cboPrintProcess" when the break hits that line?
0
 
SteveL13Author Commented:
That didn't work.  All four tabs still display even when Me.cboPrintProcess = "Inkjet"
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Also - are you SURE those are the right names? I just tested the code on my machine and it works to hide the tab pages.
0
 
PatHartmanCommented:
but as you can see, Access is changing the names of the controls...
Of course it is.  This is one of the side effects of using embedded spaces or special characters.  That is why experts always warn against this practice.  You can even run into a situation where Access will fail entirely since it just does a simple substitution of "_" for every offending character.

Be very careful to validate the number of spaces in your names.  Since we almost always use proportional fonts, spaces take up way less horizontal width than the average character so it is difficult to ascertain exactly how many embedded spaces your name have.

The simplest way to handle non-conforming field names is to use square brackets.  That's how Access SQL solves the problem.

Me.[Consumables - Toner].Visible = False

Are you sure these are the Names of the tab pages and not the Captions?  Open the properties dialog and verify the Name property of each tab page.  I think you will find that is your problem.
0
 
SteveL13Author Commented:
Yes,  Please see attachments.
Rates---Toner.jpg
Consum-Toner.jpg
0
 
PatHartmanCommented:
Why don't you just use well formed names.  The Caption can be whatever you want the user to see but the Name property is what is used in VBA.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I strongly agree with Pat regarding the use of well-formed names. While it seems trivial to many people (and especially to those who are just starting out in Access programming), it's quite important, and will help you avoid many common traps and pitfalls.
0
 
Rey Obrero (Capricorn1)Commented:
you need the name of the Tab Control to hide/unhide pages


Me.TabCtl0.Pages("Consumables - Toner").Visible = False
Me.TabCtl0.Pages("Rates - Toner").Visible = False
0
 
SteveL13Author Commented:
This solution worked.  Thanks.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
That's odd ... I tried the code I provided before posting here, and I was able to hide a Tab page like this:

Me.Controls("Page1").Visible = False

I didn't have to reference the Tab Control's Pages collection. Curious why it worked for me but not you ...
0
 
SteveL13Author Commented:
Yeah, I don't know.  Until I added the Tab Control's Pages collection it wouldn't hide.  ???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now