none
New instance of form closes immediately after it opens. RRS feed

  • Question

  • This works fine in one of my apps, and the code is exactly the same. Is there some Form property I can't remember that needs to be set to allow multiple instances of a Form? I'm seeing the new Form open, then it just closes after a fraction of a second.

    Private Sub btnOpenAnotherInstance_Click()
    Dim newForm As New Form_Form5
    newForm.Visible = True
    End Sub
    Monday, February 6, 2017 7:17 PM

Answers

  • Hi,

    I think what is happening is the variable newForm is getting out-of-scope as soon as the procedure (click event) finishes. You could try using a global variable instead.

    Hope it helps...

    • Marked as answer by HTHP Monday, February 6, 2017 7:49 PM
    Monday, February 6, 2017 7:38 PM
  • Wow, I just read the code a little further. When that form opens, I open a user defined class and pass it a reference to the current form. So it must be that class holding reference that keeps the new instance open. I think its referencing itself via this class during the open event. This is a side effect, not my intent when writing that other class. Interesting.
    • Marked as answer by HTHP Monday, February 6, 2017 7:49 PM
    Monday, February 6, 2017 7:48 PM

All replies

  • Hi,

    I think what is happening is the variable newForm is getting out-of-scope as soon as the procedure (click event) finishes. You could try using a global variable instead.

    Hope it helps...

    • Marked as answer by HTHP Monday, February 6, 2017 7:49 PM
    Monday, February 6, 2017 7:38 PM
  • I realized that as soon as the button event terminates, it releases the memory of the newForm variable. So I can just declare it at module level. But what is still stumping me is that my other app doesn't do this. It declares the variable in the event, and can create unlimited new instances. Bizarre?
    Monday, February 6, 2017 7:40 PM
  • Wow, I just read the code a little further. When that form opens, I open a user defined class and pass it a reference to the current form. So it must be that class holding reference that keeps the new instance open. I think its referencing itself via this class during the open event. This is a side effect, not my intent when writing that other class. Interesting.
    • Marked as answer by HTHP Monday, February 6, 2017 7:49 PM
    Monday, February 6, 2017 7:48 PM
  • Hi,

    Correct me if I'm wrong but objects are probably passed by ref, so the memory location is essentially "locked" by the other process even after the originating event has finished executing.

    Cheers!

    Monday, February 6, 2017 7:50 PM
  • multiple instances of a Form?

    Hi HTHP,

    For what purposes do you use these multiple instances?

    Imb.

    Monday, February 6, 2017 8:16 PM
  • It has to do with the workflow for the Users of my app. The users need multiple instances of this form open at once to compare information from different perspectives.
    Monday, February 6, 2017 8:45 PM
  • It has to do with the workflow for the Users of my app. The users need multiple instances of this form open at once to compare information from different perspectives.

    I hope you don't mind me asking this. Perhaps it was better to start a new thread.

    Are the multiple forms with different WHERE conditions? Or do they display different fields from the same underlying query? Or do they display completely different information?

    I try to understand how these multiple instances compare to my way of working, where I use the same form for completely different situations.

    Imb.

    Monday, February 6, 2017 9:51 PM
  • Its pretty simple actually. Each new instance just allows the user to filter for details based on different WHERE criteria. Its really just a matter of needing multiple instances of that exact form so the users can see them all at once on their screen as they make adjustments to the records at the same time.

    In other words, I am using the exact same form for the exact same reasons.
    Tuesday, February 7, 2017 1:25 PM