• Multiple Instances of same form

    Author
    Topic
    #461158

    I have read [post=”565662″]Post 565662[/post], and seen the link that points to MS KB :How to Open multiple instances of the same form

    The examples all seem to involve opening a second instance from the form itself. That is not what I have been asked to do.

    From a continuous form, the user selects a record, then clicks a button to open a second form at the selected record.

    Code:
     
    		   If Not IsNull(Me.PracticeID) Then
    					stLinkCriteria = "[PracticeID]=" & Me![PracticeID]
    			End If
    			stDocName = "frmPracticeDetails"
    			DoCmd.OpenForm stDocName, , , stLinkCriteria

    They would like to be able to leave frmPracticeDetails open, return (somehow) to the list form, select another Practice and view its details.
    Returning to the continuous form, selecting a different record and clicking the button a second time does not work (I did not expect it to). frmPracticeDetails then shows the details of the second practice, but the first practice is now gone.

    I tried this.

    Code:
    	If Not isLoaded(stDocName) Then
    			   DoCmd.OpenForm stDocName, , , stLinkCriteria
    		   Else
    			   Dim frmPracticeDetailsx As Form
    			   Set frmPracticeDetailsx = New Form_frmPracticeDetails
    			   frmPracticeDetailsx.Filter = stLinkCriteria
    			   frmPracticeDetailsx.FilterOn = True
    			   frmPracticeDetailsx.SetFocus
    		   End If

    If the form is already open when the button is clicked, a form flashes up briefly but closes immediately and I am left at the list.

      [*]Can you do what I want?
      [*] If so does it involve something much more complicated than what I have tried above?
    Viewing 1 reply thread
    Author
    Replies
    • #1168835

      I have attached a small sample database based on Allen Browne’s Managing Multiple Instances of a Form, modified to demonstrate how to open a filtered form.

      Open frmClientSearch and click the “Show selected client” button to open an instance of the other form frmClient for the selected client.
      Each new form will be offset slightly from the previous one, eventually it will disappear from the screen.
      Clicking “Close detail windows” closes the forms and resets the position.

      There is no check against opening multiple windows on the same record.

    • #1168844

      I forgot to mention that the essential part is adding the form object of the new instance to a collection. This keeps the form open after the event procedure has finished. As you can see in CloseAllClients, removing the object from the collection instantly closes the instance.

      • #1168863

        Thanks for these two posts Hans. I have just downloaded the demo, and will look at it in depth.

        • #1168882

          I have attached a slightly modified version that prevents opening multiple instances for the same ClientID. If there is already an instance for the selected ClientID, that form is activated.

          • #1168937

            Thanks for all this. I have been able to get it to work.

            A few issues arose (not surprisingly).

              [*]The Forms![frmPracticeDetails]![PracticeID] syntax can’t be used. frmPracticeDetails has some subforms with combo boxes, so I had to set the row source dynamically to an sql string.
              [*]Access seems happy for multiple instances of the subforms to be open at the same time, with the combo boxes having different row sources. I had thought that might create a problem.
              [*]frmPracticeDetails is quite large and has a number of subforms. My preference is to maximize it, but I need to be able to see the list of practices. Making frmPracticeDetails a popup form works well visually, but I actually need to be able to open other forms in front of frmPracticeDetails (e.g. they need to be able to look at the Doctors at the Practice for example)
              [*]So the result of all this a visual jumble on the screen. I don’t like it at all, but I will give it a go.

            Thanks again

            • #1168954

              I have now reverted to keeping all the forms maximized, and made a few changes to support this.
              I will try this out tomorrow with the users and see what they think.

    Viewing 1 reply thread
    Reply To: Multiple Instances of same form

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: