Changing Subforms Within a Mainform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pezzini
    New Member
    • Feb 2012
    • 1

    #1

    Changing Subforms Within a Mainform

    I have a mainform which I want to set up as a user interface. There are no options on this form other than buttons created to open other forms. I've created the forms and they all work if I simply want to open them over the top of the main form, but what I would like to be able to click on the 'menu' item buttons to change the central subform in the body of the screen.

    Any body any ideas how this can be done? I tried several codes:

    Attempt 1
    Code:
    me.subfrmcontrol.sourceobject = "formname"
    Attempt 2
    Code:
    With Me.subformcontrol
        .LinkChildFields = ""
        .LinkMasterFields = ""
        .Form.Requery
    EndWith
    But these just gave me errors, so either I've missed something like setting variables, or there's another way of doing this.

    Any help would be appreciated.
    Thanks
    Pezzini
    Last edited by NeoPa; Feb 6 '12, 04:24 PM. Reason: Added mandatory [CODE] tags for you
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Are you saying you'd like to have a main menu-type form, which is always available, and to show various optional forms in a subform of that same main form? So the whole system will run with the main form open and active all the time, but other forms (individually and singly) are also available via the subform on the main form?

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Your Syntax is correct, as long as subFrmControl refers to the Sub-Form 'Control' itself, and not a Form Name. The following Code will load any one of three Forms into the Sub-Form Control named subFrmControl:
      Code:
      Dim strSourceSubForm As String
      
      'strSourceSubForm = "subFrm2"
      'strSourceSubForm = "subfEmployees"
      strSourceSubForm = "frmInputView"
      
      With Me![subFrmControl]
        .SourceObject = strSourceSubForm
        .LinkMasterFields = ""
        .LinkChildFields = ""
          .Requery     'Form qualifier not needed
      End With

      Comment

      • Gail Williams
        New Member
        • Feb 2012
        • 12

        #4
        @NeoPa - yes, that is exactly what I'm trying to do.

        @ADezii - will give that a go when I get to work in the morning.

        Thanks both

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          I assume you are the erstwhile Pezzini in a new guise Gail, who has simply lost the previous sign-in details. That way I can allow you to take over the thread (which would otherwise be a hijack). If so, then please don't continue to use the Pezzini account as we don't allow members to use multiple accounts.

          ADezii is correct when they indicate that the SubForm Control itself has a .Requery method that can be called. The bang (!) instead of the dot (.) is not particularly important though, and your syntax was already perfectly valid assuming the control name doesn't clash with any other reserved words or contain any space character within it. Brackets handle all names as expected though, so are always good to know about. Otherwise the only code required is the .Requery call.
          Code:
          With Me.[subfrmcontrol]
              .SourceObject = "FormName"
              Call .Requery
          End With
          Nothing in ADezii's code will cause a problem of course, but I want you to understand how close you were to getting it right in the first place, and also which parts of the suggested code are the relevant ones. Only the need to include both lines in the one workable solution was missing.

          Comment

          • Gail Williams
            New Member
            • Feb 2012
            • 12

            #6
            This worked for me. Thanks both for your help.

            @NeoPa - I'll try and figure out what the first account was and see if I can log in that way in future.

            Thanks again

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              Good for you Gail. Whichever account you choose is fine - but we prefer only one is used consistently. My response to your PM explains it more fully :-)

              Comment

              Working...