How to create multiple instances of the same form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sueb
    Contributor
    • Apr 2010
    • 379

    How to create multiple instances of the same form?

    Is there a way to specify that selecting a Switchboard option (that brings up a form) creates another instance of that form v. changing focus to the existing one?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Opening Multiple Instances of a Form can be a little tricky. This Demo should help you out.
    Attached Files

    Comment

    • sueb
      Contributor
      • Apr 2010
      • 379

      #3
      Thanks for this. A couple of questions:

      I'm assuming that the code in OpenAClient is what I'd need to implement? What is the purpose of the collection mentioned in that code? The names are a little cryptic, so I feel very uncertain about understanding the implications of what's going on in that module. What does a "caption" do for me?

      Also, why is there a special module to close forms? Why can't the user just close whichever instance they want to?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        I'm assuming that the code in OpenAClient is what I'd need to implement?
        Correctamundo!
        What is the purpose of the collection mentioned in that code?
        To hold and manage the various Form Instances.
        The names are a little cryptic, so I feel very uncertain about understanding the implications of what's going on in that module. What does a "caption" do for me?
        All Instances of a Form are exactly the same as far as Name goes, so the Caption is a method of telling one from another.
        Also, why is there a special module to close forms? Why can't the user just close whichever instance they want to?
        Yep, the User can manually Close an Instance he/she wants to.

        Comment

        • sueb
          Contributor
          • Apr 2010
          • 379

          #5
          As far as managing the form instances, what actions are we talking about?

          Comment

          • sueb
            Contributor
            • Apr 2010
            • 379

            #6
            Also, I don't seem to be able to add this module as a selection on the Switchboard, which is where I want it.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              The Switchboard Item calls the Public OpenAClient() Function.

              P.S. - See Attachment.
              Attached Files

              Comment

              • sueb
                Contributor
                • Apr 2010
                • 379

                #8
                I copied and pasted that code into my module (changing the name of the form to match mine) and added it to my Switchboard, but when I tried to execute it, the screen inside my Access window flashed (as though it were going to create the new form) and then nothing else happened. The Switchboard was still there, but there was no form.

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  TO create an Instance of your Form:
                  1. Remove all references to the Collection.
                  2. Declare frm as Public in a Standard Code Module.
                  3. Download the Attachment for a visual.
                  Attached Files

                  Comment

                  • sueb
                    Contributor
                    • Apr 2010
                    • 379

                    #10
                    Well, I hate to be so dense, but it's still not working at all, just that flash. Here's what I have, and "OpenAClien t" is on my Switchboard:

                    Code:
                    Option Explicit
                    'Purpose:   Open an independent instance of form frmClient.
                    Public frm As Form
                    
                    Function OpenAClient()
                        'Open a new instance, show it, and set a caption.
                        Set frm = New Patient_IUR_Overview
                        frm.Visible = True
                        frm.Caption = frm.Hwnd & ", opened " & Now()
                    End Function
                    What am I missing?

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      1. Is Public frm As Form declared in a Public Code Module?
                      2. Do you wish to create a Single Instance of the Form or Multiple Instances?
                      3. If you cannot get this issue resolved, can you Upload the DB to either this Forum or my personal E-Mail Account?

                      Comment

                      • sueb
                        Contributor
                        • Apr 2010
                        • 379

                        #12
                        Where do I find out whether the module it's in is public? And I do want to create multiple instances of the form; single instance has been working great all along--the whole point of this particular question was for my users to be able to have more than one instance of this form open at a time.

                        Comment

                        • ADezii
                          Recognized Expert Expert
                          • Apr 2006
                          • 8834

                          #13
                          It's not the Module that is Public, it is the Declaration of the frm Variable. Look at the latest Attachment.

                          Comment

                          • sueb
                            Contributor
                            • Apr 2010
                            • 379

                            #14
                            In the code that I posted, is it not correct?

                            Comment

                            • ADezii
                              Recognized Expert Expert
                              • Apr 2006
                              • 8834

                              #15
                              Yes, as long as Public frm As Form is Declared in a Standard Code Module.

                              Comment

                              Working...