Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide Tab Page Based Upon Subform Control 2

Status
Not open for further replies.

cstuart79

Technical User
Nov 2, 2009
171
US
My main form has 4 tabs. I would like to either hide or make visible tab4 based upon the value of a control located in a subform on tab3. I have attempted to use the following code in the main form "on current" event but it does not yield any results.

tab3 subform = Master_Key
tab3 subform control = chkDR
tab3 name = tbProdCarl
tab4 name = tbDRPhilly
main form = CLIENTS

Private Sub Form_Current()
If Me.Parent.Master_Key.chkDR.Value = True Then
Sheets("tbDRPhilly").Visible = True
Else
Sheets("tbDRPhilly").Visible = False
End If
End Sub


 
I'd try something like this:
Code:
Private Sub Form_Current()
Me![name of tab control].Pages("tbDRPhilly").Visible = Me!Master_Key.Form!chkDR.Value
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The main form doesn't have a "Parent" property. I'm not sure where you found the "Sheets" property. Try the following substituting your tab control name:
Code:
Me.TabCtlName.Pages("tbDRPhilly").Visible = _
  (Me.Master_Key.Form.chkDr = True)

Duane
Hook'D on Access
MS Access MVP
 
thanks guys. works fine in "on current" event; however, visibility does not change upon changing "chkDR" value (need to click different client first before changes are seen). i tried to put the same code in "after update" event but this does not show immediate changes either. any suggestions?

Private Sub Form_AfterUpdate()
Me.TabCtl88.Pages("tbDRPhilly").Visible = Me.Master_Key.Form.chkDR.Value
End Sub
 
it is in the "after update" event of the main form "CLIENTS" just like the "on current" code. is this the wrong place?
 
What determines the need to hide or display? I thought you stated it was the value of chkDR. Where is chkDR located, in the main form or elsewhere? If it's not on the main form then using the after update of the main form won't do you any good.

Duane
Hook'D on Access
MS Access MVP
 
chkDR does determine the need to hide or display. chkDR is control located on subform "Master Key". when i put the following code on "after update" event of subform "Master Key" i get the error "Method or data member not found".

Private Sub Form_AfterUpdate()
If Me.chkDR.Value = True Then
Me.DR_Label.BackColor = RGB(0, 255, 0)
Me.DR_Label.FontBold = True
Me.TabCtl88.Pages("tbDRPhilly").Visible = True
End Sub

i get the same error when applying code to "after update" event of control "chkDR".

Private Sub chkDR_AfterUpdate()
If Me.chkDR.Value = True Then
Me.DR_Label.BackColor = RGB(0, 255, 0)
Me.DR_Label.FontBold = True
Me.TabCtl88.Pages("tbDRPhilly").Visible = True
Else
Me.DR_Label.BackColor = RGB(255, 255, 255)
Me.DR_Label.FontBold = False
Me.TabCtl88.Pages("tbDRPhilly").Visible = False
End If
End Sub
 
the line that seems to be causing the error "Method or data member not found" is:

Me.TabCtl88.Pages("tbDRPhilly").Visible = True

with "TabCtl88" highlighted
 
I had guessed that might be the line. Can you respond to my question "Did you not understand my reply on 9 Dec 09 12:42?"

It is important that you:
[ol]
[li]Provide all significant details such as table and field names and types, form and control names, error messages, results, lines causing errors, what you tried,...[/li]
[li]describe what you want to happen[/li]
[li]read and respond to the suggestions and questions from people who attempt to help you[/li]

[/ol]

Duane
Hook'D on Access
MS Access MVP
 
CLIENTS" is the parent form that has the tabs located on it. I placed the code in the "after update" event of "CLIENTS". Also tried placing it in the "after update" event of both the subform "Master Key" and control "chkDR" (located on subform "Master Key", but neither worked.

My main form "CLIENTS" has 4 tabs. I would like to either hide or make visible tab "tbDRPhilly" based upon the value of a control "chkDR" located in a subform "Master Key" on another tab "tbProdCarl".

tab3 subform = Master_Key
tab3 subform control = chkDR
tab3 name = tbProdCarl
tab4 name = tbDRPhilly
main form = CLIENTS

When the following code was placed in "on current" event of main form "CLIENTS" it works but does not take affect until records have been changed:

Private Sub Form_Current()
Me.TabCtl88.Pages("tbDRPhilly").Visible = Me.Master_Key.Form.chkDR.Value
End Sub

In order to see changes immediately after updating, I attempted to place the following code in "after update" event of main form "CLIENTS", subform "Master Key", and control "chkDR":

Private Sub Form_AfterUpdate()
If Me.chkDR.Value = True Then
Me.DR_Label.BackColor = RGB(0, 255, 0)
Me.DR_Label.FontBold = True
Me.TabCtl88.Pages("tbDRPhilly").Visible = True
End Sub

None of these worked and only yielded an error "Method or data member not found" with "TabCtl88" in the following line highlighted:

Me.TabCtl88.Pages("tbDRPhilly").Visible = True

The rest of the code:
Me.DR_Label.BackColor = RGB(0, 255, 0)
Me.DR_Label.FontBold = True
references (and functions properly) a change to the color of control "chkDR"'s label "DR_Label".
 
Since the tab control is on the parent form, any code in a subform that references something in the main form or a different subform must use the Parent property.

Try:
Code:
Me.Parent.TabCtl88.Pages("tbDRPhilly").Visible = True


Duane
Hook'D on Access
MS Access MVP
 
that did it! sorry it took me a while to understand about the "parent".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top