Tab Visibility based upon combo box value

B

BillA

I am attempting to hide and make visible a Tab/Page based upon a value from a
combo box on the main form.

This is what I’m working with:
Main form: Single page
Tab/Page -Name: PageRenewal; Page Index: 2
Subform – Name: Tab_Renew; Source: Tab_renew
The combo box -Name: StatusDescriptionID (a value from a lookup table - in
this case "Open" or ID number "2")

After numerous attempts, without success; I’d appreciate any guidance offered.

Thank you,
Bill
 
G

George Nicholson

(In cboStatusDescriptionID_AfterUpdate and probably Form_Current)

Where "PageRenewal" is the name of the Tab control itself, not an individual
page on that tab (not 100% clear from your post).

Me.PageRenewal.Pages(2).Visible = (Me.cboStatusDescription = 2)

or something like:

Select Case Me.cboStatusDescription
Case 2
Me.PageRenewal.Pages(2).Visible = True
Case Else
Me.PageRenewal.Pages(2).Visible = False
End Select
 
B

BillA

Hello George,

I believe I understand you, and would have to say the tab control is
PageRenwal. Within Design View, if I click on the tab in question it reveals
the name as PageRenewal, so your suggestions seem on the mark.

I was unsuccessful in testing your suggestions.
I received compile errors: “Method or data member not found†and Ambiguous
Name errors

Any suggestions would be appreciated.
Thanks,
Bill
 
G

George Nicholson

-"Ambiguous name" errors: you have 2 (or more) procedures with identical
names, probably in the same module. You need to find one of them and rename
it. The error message probably told you what the offending procedure name
is, so it should be easy to track them down with Edit>Find in the VBE.

-"Method or data member not found": on what line(s)? What is highlighted?
 
B

BillA

Hi George,

Thanks for recommendations; I'll give them a try and let you know what I
find... may take an day or so as I will be out of the office.

Thanks again,
Bill
 
B

BillA

Hello George,

Your first suggestion resulted in a “method or data member not found,†that
error highlights the following code:

Private Sub StatusDescriptionID_AfterUpdate()
Me.PageRenewal.Pages(2).Visible = (Me.StatusDescriptionID = 2)
Specifically the “.StatusDescriptionID†within the parenthesis was
highlighted.

As for the ambiguous name error. I placed the Select Case code in both the
AfterUpdate and Current. This is the code used in both:

Private Sub Form_Current()
Select Case Me.StatusDescriptionID
Case 2
Select Case Me.PageRenewal.Pages(2).Visible = True
Case Else
Me.PageRenewal.Pages(2).Visible = Visible = False
End Select
End Sub

It turns out I already have an event name “Form_Current ().â€

I removed the _Current code leaving just the AfterUpdate and received the
same “Compile error: method or data member not found†as the previous
attempt. The offending line was: “Select Case
Me.PageRenewal.Pages(2).Visible = True†Specifically the “.Pages†was
highlighted.

Although I am still feeling my way through Access VB, I tried many different
iterations of ‘code’ (using term loosely). The closest I got something
working, with limitations, was this:

Private Sub StatusDescriptionID_AfterUpdate()
Me!PageRenewal.Visible = Nz(Me.StatusDescriptionID = 2, False)
Me.PageAmendment.Visible = Nz(Me.StatusDescriptionID = 2, False)
Me.PageApplication.Enabled = Nz(Me.StatusDescriptionID = 1, True)
End Sub

Probably not the best coding... but I grabbing straws right now.

I added an additional Tab and the enabling/disabling of the Application
page. This worked only when I physically changed information in the combo
box. I couldn’t get it to work OnCurrent as forms opened – previously “Openâ€
projects didn’t cause the desired visibility of the tab and the ‘Enabled’
function was somewhat suspect – sometimes it worked… sometimes it didn’t.

Any advice would be appreciated.
Thanks again,
Bill
_____________________________________________________________
 
B

BillA

Hello George:

I went back and did a little studying (and a whole lot of trial and error)
of your suggestions and found them to be on target.

The code below is what I finally used and it works to perfection. I also
call this code from the the forms current event.
Thanks again for your time and direction.
Bill

Private Sub cboStatus_AfterUpdate()
Select Case Me.cboStatus
Case 2
Me.TabPages.Pages(2).Visible = True
Me.TabPages.Pages(3).Visible = True
Me.TabPages.Pages(1).Enabled = False
Case Else
Me.TabPages.Pages(2).Visible = False
Me.TabPages.Pages(3).Visible = False
Me.TabPages.Pages(1).Enabled = True
End Select
End Sub
 
G

George Nicholson

Glad you got it working. Seemed like one issue was trying to use Pages(#) on
what appeared to be the individual pages rather than the 'master' Tab
control itself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top