Form Reference to Labels

D

DJW

I have a main form called "frm_Main".

The main form has three tabbed pages.

Each page contains a subform (i.e. page1 has subform1, page 2 has subform2,
etc.)

My main form has a two labels (Label28 and Label40).

I am trying to write code to reference the labels on the main form when I
click on the page tab. What I'm trying to do is when I click on the tab to
page1, the Label28 is visible on the main form and label40 is not. When I
click on the tab to select page2, the opposite occurs... Label28 is not
visible an Label40 is.

Here is what I've tried so far with no success. I'm looking for correct
code reference to the label and the correct place to place the code.

Private Sub Form_GotFocus()
Forms![Frm_Main].[Label28].Visible = False
Forms![Frm_Main].[Label40].Visible = True
End Sub

Any help appreciated.
 
A

Allen Browne

Put your code into the Change event of the tab control.
Examine the tab control's Value to see which page is selected.
The value will be the same as the PageIndex of the page control.
 
W

Wayne Morgan

Instead of the Got Focus event of the subform itself, try the Enter event of
the subform control that holds the subform. Since this control is on the
main form, the syntax would be as below.

Me.Label28.Visible = False
Me.Label40.Visible = True

However, you may need to see if the focus is actually going to these
subforms when you click on the tabs. If it is not, you may need to use the
Change event of the tab control. You can tell which page you're on by
getting the Value property of the tab control. This will return the page's
index number (zero based). If you need to get the name of the page (what it
says on the tab) instead of its index number, you can use the following:

strPageName = Me.TabCtl0.Pages(Me.TabCtl0.Value).Name
 

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