Solved

Trying to hide tabs on a form

Posted on 2014-03-31
12
234 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

895 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

17 Experts available now in Live!

Get 1:1 Help Now