Enabled property use on Tab Control "On Change"

B

Barry

I have a Tab Control, "TabCt", which includes two Tabs (aka Pages) containing
subforms(irrelevent though), "Tab1" and "Tab2". This is on a main form,
"Form1", which includes a text box "txtbox" (names for example only). I
would like to have the text box appear only when "Tab1" is selected/active,
but not for "Tab2". There are limited options in the event properties for
tab controls, so I have chosen to run the code (below) based on the 'On
Change' property. Currently, based on the code below, the text box
disappears when selecting either tab. I am reaching out for help in
adjusting my code (below) to work correctly. I am wondering if possibly the
code needs to be adjusted so that it is not tied to the 'On Change' tab
control property as well, but I do not know how to adjust it so. I read in
Help that the Enabled Property applies to Tab Control groups (therefore I
wonder if it cannot apply to individual tabs).

Private Sub TabCt_Change()
Dim txtbox As TextBox
Set txtbox= [Forms]![Form1]![txtbox] 'because it is on the main form

If Me!Tab2.Enabled Then
txtbox .Visible = False
Else
txtbox.Visible = True

End If
End Sub
 
G

Graham Mandeno

Hi Barry

Each tab page has a PageIndex property. You will probably find that Tab1
has 0 and Tab2 has 1.

The Value property of the tab control is the PageIndex of the currently
selected page, so that is what you should check for:

Private Sub TabCt_Change()
txtbox.Visible = (TabCt.Value = 1)
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