Solved

Trying to hide tabs on a form

Posted on 2014-03-31
12
243 Views
Last Modified: 2014-04-01
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
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 84
ID: 39967454
Try this:

Me.Controls("Consumables - Toner").Visible = False
Me.Controls("Rates - Toner").Visible = False
0
 
LVL 84
ID: 39967513
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
 

Author Comment

by:SteveL13
ID: 39967497
That didn't work.  All four tabs still display even when Me.cboPrintProcess = "Inkjet"
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 84
ID: 39967527
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
 
LVL 37

Expert Comment

by:PatHartman
ID: 39967569
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
 

Author Comment

by:SteveL13
ID: 39967561
Yes,  Please see attachments.
Rates---Toner.jpg
Consum-Toner.jpg
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 39967579
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
 
LVL 84
ID: 39967705
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
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39967732
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
 

Author Closing Comment

by:SteveL13
ID: 39969112
This solution worked.  Thanks.
0
 
LVL 84
ID: 39969614
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
 

Author Comment

by:SteveL13
ID: 39969756
Yeah, I don't know.  Until I added the Tab Control's Pages collection it wouldn't hide.  ???
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question