Tab display when checked

B

Bill

OK I've been working on a form that displays a tab only when a box it
checked. How can I do this?

Private Sub Check122_Click()
If Me!Check122 = True Then
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = True
Else
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = False
End If

End Sub
 
G

Graham Mandeno

Hi Bill

You don't mention what the problem is. Does this not work? Do you get any
error message?

Is the tab control on a subform, or is IR_Main the main form? If the latter
then your reference is invalid. You should just say:
Me.TabCt176.Pages(2).Visible = True

(Note the .Item is unnecessary)

A few other (gratuitous) tips :)

1. Use the AfterUpdate event, not the Click event

2. Always rename a control to something meaningful after creating it.
"TabCt176" and "Check122" mean nothing, so rename them to, say, "tbcOptions"
and "chkShowWidgetsPage".

3. The page with index number 2 will have its own name, say "tpgWidgets", so
you can avoid future problems by referring to it by name:
Me.tpgWidgets.Visible = True

Also, you cannot hide a tab page if the current focus is on a control on
that page, so you should .SetFocus to another control first if necessary.
 
B

Bill

Thank you Graham. I'm not very good at this stuff and really trying to self
teach myself.

Anyway, the way the form is setup is IR_Main is the main form then there are
7 TABS which contact different forms. In the example I'm trying to work on I
want the user to check a box if they are inputing a specific type of item.
If they are then the tab (containing the subform) will display. If the box
is not checked, the page will not display. I agree about naming the items
appropriately as it makes it very hard to find things if not. So I've
updated my check box with the following code and I get the error Complie
Error - Method or Data member not found.

Private Sub chkGeneralLiability_AfterUpdate()
If Me.chkGeneralLiability = True Then
Me.TabCt176.Pages(2).Visible = True
Else
Me.TabCt176.Pages(2).Visible = False
End If

End Sub

I appreciate your help. I'm doing this for my work as I created a simple
database and now they have requested me to look at other things. I'm not in
IT but I love trying to figure this out!

Thanks


Graham Mandeno said:
Hi Bill

You don't mention what the problem is. Does this not work? Do you get any
error message?

Is the tab control on a subform, or is IR_Main the main form? If the latter
then your reference is invalid. You should just say:
Me.TabCt176.Pages(2).Visible = True

(Note the .Item is unnecessary)

A few other (gratuitous) tips :)

1. Use the AfterUpdate event, not the Click event

2. Always rename a control to something meaningful after creating it.
"TabCt176" and "Check122" mean nothing, so rename them to, say, "tbcOptions"
and "chkShowWidgetsPage".

3. The page with index number 2 will have its own name, say "tpgWidgets", so
you can avoid future problems by referring to it by name:
Me.tpgWidgets.Visible = True

Also, you cannot hide a tab page if the current focus is on a control on
that page, so you should .SetFocus to another control first if necessary.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bill said:
OK I've been working on a form that displays a tab only when a box it
checked. How can I do this?

Private Sub Check122_Click()
If Me!Check122 = True Then
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = True
Else
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = False
End If

End Sub
 
B

Bill

Ok it was that simple!!! I used your suggestion as it dawned on me
everything is named so I should be able to call it that way. Once I did,
wala it worked! Thanks!!


Private Sub chkGeneralLiability_AfterUpdate()
If Me.chkGeneralLiability = True Then
Me.GeneralLiability.Visible = True
Else
Me.GeneralLiability.Visible = False
End If
End Sub


Graham Mandeno said:
Hi Bill

You don't mention what the problem is. Does this not work? Do you get any
error message?

Is the tab control on a subform, or is IR_Main the main form? If the latter
then your reference is invalid. You should just say:
Me.TabCt176.Pages(2).Visible = True

(Note the .Item is unnecessary)

A few other (gratuitous) tips :)

1. Use the AfterUpdate event, not the Click event

2. Always rename a control to something meaningful after creating it.
"TabCt176" and "Check122" mean nothing, so rename them to, say, "tbcOptions"
and "chkShowWidgetsPage".

3. The page with index number 2 will have its own name, say "tpgWidgets", so
you can avoid future problems by referring to it by name:
Me.tpgWidgets.Visible = True

Also, you cannot hide a tab page if the current focus is on a control on
that page, so you should .SetFocus to another control first if necessary.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bill said:
OK I've been working on a form that displays a tab only when a box it
checked. How can I do this?

Private Sub Check122_Click()
If Me!Check122 = True Then
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = True
Else
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = False
End If

End Sub
 
G

Graham Mandeno

Hi Bill

I'm glad you got it all working. Thanks for the feedback!
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bill said:
Ok it was that simple!!! I used your suggestion as it dawned on me
everything is named so I should be able to call it that way. Once I did,
wala it worked! Thanks!!


Private Sub chkGeneralLiability_AfterUpdate()
If Me.chkGeneralLiability = True Then
Me.GeneralLiability.Visible = True
Else
Me.GeneralLiability.Visible = False
End If
End Sub


Graham Mandeno said:
Hi Bill

You don't mention what the problem is. Does this not work? Do you get
any
error message?

Is the tab control on a subform, or is IR_Main the main form? If the
latter
then your reference is invalid. You should just say:
Me.TabCt176.Pages(2).Visible = True

(Note the .Item is unnecessary)

A few other (gratuitous) tips :)

1. Use the AfterUpdate event, not the Click event

2. Always rename a control to something meaningful after creating it.
"TabCt176" and "Check122" mean nothing, so rename them to, say,
"tbcOptions"
and "chkShowWidgetsPage".

3. The page with index number 2 will have its own name, say "tpgWidgets",
so
you can avoid future problems by referring to it by name:
Me.tpgWidgets.Visible = True

Also, you cannot hide a tab page if the current focus is on a control on
that page, so you should .SetFocus to another control first if necessary.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bill said:
OK I've been working on a form that displays a tab only when a box it
checked. How can I do this?

Private Sub Check122_Click()
If Me!Check122 = True Then
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = True
Else
Me.Form_IR_Main.TabCt176.Pages.Item(2).Visible = False
End If

End Sub
 

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