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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide a subform on a subform

Status
Not open for further replies.

PRMiller2

Technical User
Jul 30, 2010
123
I have a form called fmnuMain that contains a tab control with a number of pages. I have a table populated with Form names and whether or not they are accessible based on that user's security level. On startup, I loop through that table, obtain the number of forms for which the user has access, and then show or hide the appropriate number of page tabs. I then loop through those page tabs and set the Tag text to contain the subform name I want loaded when a page tab is clicked.

When the user clicks a page tab, the subform control ("sfmMenu") on that page loads the form named on the Tag text of that page.

I have one tab called Admin, where the sourceobject of the sfmMenu control will load sfmAdministration. In an effort to reduce the number of tabs, I have a listbox control that allows users to select various admin options. One of those options opens sfmStaff (in control sfmAdminComponent), which itself resides in sfmAdministration (in control sfmMain). When the user clicks the option in the listbox that loads this form, I hide the listbox, change sfmAdminComponent to visible, and sfmAdminComponent.SourceObject to equal sfmStaff.

No problems there.

I added a close button to sfmStaff. When clicked, I want the sfmStaff to disappear and then sfmAdministration tab to reappear, complete with the list boxes. I have really been struggling with syntax here. When attempting to hide the subform, I receive the error message, "You can't hide a control that has the focus." I receive this message even though I move the focus to a control on my main form. Here's what I've got:

Code:
Private Sub cmdClose_Click()
On Error GoTo Err_Handler

    Forms("fmnuMain").SetFocus
    Forms!fmnuMain.SetFocus
    
    Forms("fmnuMain")("txtFocus").SetFocus
    
    Forms!fmnuMain.sfmMenu.Form!sfmAdminComponent.Visible = False
    Forms!fmnuMain.sfmMenu.Form!sfmAdminComponent.SourceObject = ""
    Forms!sfmAdministration.lstCategory.Visible = True
    Forms!sfmAdministration.lstItem.Visible = True

Exit_Handler:
    Exit Sub

Err_Handler:
    Call LogError(Err.Number, Err.Description, "sfmStaff.cmdClose_Click()", , True)
    Resume Exit_Handler

End Sub

Any recommendations?
 
I think you're not referencing the subform correctly. I forget the exact syntax off-hand, and I usually just search it online to find it... but it's something like this..

Forms!MyMainForm!MySubform!Form.Visible = false

Well, that's my initial stab at what you want, but give it a try, and if that isn't correct, do some searching on referencing subform conrols from form, and you should find what you need.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Yeah, I'm sure that makes for MUCH easier referencing. [thumbsup2]

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top