[RESOLVED] [VBA] Open Form in SubForm [Urgent]
I have a form called frmIndex with a form header, detail and footer.
The header just contains a logo and title, the footer contains nothing.
The bit I am focused on though is the detail section which contains a subform (the subform has the name: IndexFrame), which is currently displaying frmLogon within it.
when the user clicks a button I want IndexFrame to change its SourceObject from frmLogon to frmMenu.
How do I alter this to do what I am aiming to acheive:
VB Code:
Private Sub Command11_Click()
Dim Index As New Form_frmIndex
Index.IndexFrame.SourceObject = frmMenu
End Sub
Why doesn't that work, seems right to me? I also tried it with frmMenu in "" No luck
Thanks, Emdiesse
Re: [VBA] Open Form in SubForm [Urgent]
I assume you are using Access.
You must change the SourceObject of IndexFrame in the active instance frmIndex. Your code is creating and changing a new instance of frmIndex, not the one that you are seeing on your screen. To get the instance of the form that you see on you screen, you must get it from the Forms collection or reference Form_frmIndex without directly without declaring it as a new variable.
The following code should work.
VB Code:
Private Sub Command11_Click()
Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
End Sub
or
VB Code:
Private Sub Command11_Click()
form_frmIndex.IndexFrame.SourceObject = "frmMenu"
End Sub
You might have to set focus to a control outside the current subform.
Re: [VBA] Open Form in SubForm [Urgent]
Quote:
Originally Posted by kaffenils
I assume you are using Access.
You must change the SourceObject of IndexFrame in the active instance frmIndex. Your code is creating and changing a new instance of frmIndex, not the one that you are seeing on your screen. To get the instance of the form that you see on you screen, you must get it from the Forms collection or reference Form_frmIndex without directly without declaring it as a new variable.
The following code should work.
VB Code:
Private Sub Command11_Click()
Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
End Sub
or
VB Code:
Private Sub Command11_Click()
form_frmIndex.IndexFrame.SourceObject = "frmMenu"
End Sub
You might have to set focus to a control outside the current subform.
Thanks :)
Sorry, I alsways forget this part of the forum deals with more than access :D