Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to hide tabs on a form

Posted on 2014-03-31
12
Medium Priority
?
250 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 85
ID: 39967454
Try this:

Me.Controls("Consumables - Toner").Visible = False
Me.Controls("Rates - Toner").Visible = False
0
 
LVL 85
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 85
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 40

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 40

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 85
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 2000 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 85
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

971 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