Open within SubForm

emdiesse

Registered User.
Local time
Today, 23:28
Joined
Feb 1, 2006
Messages
36
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:
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
 
Last edited:
Your code is just work, i.e. not Access syntax. The following resets your subform sourceobject.

Forms!frmIndex!IndexFrame.SourceObject = frmMenu

Note that the new subform is referenced IndexFrame, regardless of the sourceobject. This has a beneficial effect, in that VBA code doesn't have to be duplicated for multiple sourceobjects, it can be put in a class module.

Note also that you need to use a different naming convention so that object/control names also indicate the the object/control (data) type. Otherwise, code become very obscure two weeks after you finish it. The "Hungarian nameing convention" is commonly used with Access.
 

Users who are viewing this thread

Back
Top Bottom