A1VBCode Forums

VBA .enabled property use on Tab Control's "On Change" event


http://www.a1vbcode.com/vbforums/Topic27443.aspx

By Barry - 4/13/2009

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 TextBoxSet txtbox= [Forms]![Form1]![txtbox]  'because it is on the main formIf Me!Tab2.Enabled Then    txtbox .Visible = False Else    txtbox.Visible = TrueEnd IfEnd Sub