trying to reference tab on subform (1 Viewer)

BennyLinton

Registered User.
Local time
Today, 13:57
Joined
Feb 21, 2014
Messages
263
I have a field I need to reference from my subform's tab's control to my main form like:

If MainForm.... Tab... Control = 2 Then
Mainform.Label1.Visible = True

Here are the names of the forms/controls in their hierarchy:

frmMain
frmSubFormCosts
tabFurniture
txtValue

what would be a syntax that would work? Thanks! Benny
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:57
Joined
Feb 19, 2002
Messages
43,266
Tabs do not alter the way a control is referenced. What will alter the reference is whether the tabs contain subforms or not.

You will need to control the main form from the subform not vice versa. If the code is placed in the main form, it will run in the mainform's Current event most likely. However, the subform shows multiple records so exactly which subform record did you want to reference?

Use the subform's Current event or AfterUpdate event or possibly both to alter the visible property of the main form control and you just need to use the Me.Parent reference.
Code:
If Me.txtValue = 2 Then
    Me.Parent!Label1.Visible = True
End If
As you click through the subform going record to record, the label on the main form will change to reflect the value in the CURRENT subform record.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:57
Joined
May 7, 2009
Messages
19,237
on the frmMain form you can check if TabControl->Page 2 is selected:

Private Sub Form_Current()
' Label1 refers the Label control to hide
' in the frmMain
Me.Label1.Visible = (Me.TabControl0.Value <> 2)

End Sub


Now on the Change Event of your TabControl:


Private Sub TabControl0_Change()
Call Form_Current
End Sub
 

Users who are viewing this thread

Top Bottom