Results 1 to 3 of 3

Thread: [RESOLVED] [VBA] Open Form in SubForm [Urgent]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

    Resolved [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:
    1. Private Sub Command11_Click()
    2.     Dim Index As New Form_frmIndex
    3.     Index.IndexFrame.SourceObject = frmMenu
    4. End Sub
    Why doesn't that work, seems right to me? I also tried it with frmMenu in "" No luck

    Thanks, Emdiesse
    Emdiesse

  2. #2
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    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:
    1. Private Sub Command11_Click()
    2.     Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
    3. End Sub

    or

    VB Code:
    1. Private Sub Command11_Click()
    2.     form_frmIndex.IndexFrame.SourceObject = "frmMenu"
    3. End Sub


    You might have to set focus to a control outside the current subform.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

    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:
    1. Private Sub Command11_Click()
    2.     Forms("frmIndex").IndexFrame.SourceObject = "frmMenu"
    3. End Sub

    or

    VB Code:
    1. Private Sub Command11_Click()
    2.     form_frmIndex.IndexFrame.SourceObject = "frmMenu"
    3. 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
    Emdiesse

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width