Solved

Trying to hide tabs on a form

Posted on 2014-03-31
12
233 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
  • 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
 
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 34

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 34

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 119

Accepted Solution

by:
Rey Obrero 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now