How do I open a form using same session as the application

I have this application which contains several forms. Everytime I open a form, i open one too nay sessions and when I close it, the sessions don't close out unless I close the application. Pls. advise. Thanks
LVL 1
MonNerdAsked:
Who is Participating?
 
MattiCommented:
Hi!

Remove that code, on main form put this UnloadAllForms there, it will set every form nothing, so don't need any other way to release memory.

Matti
0
 
GrahamSkanRetiredCommented:
I don't know about anybody else, but your question is hard for me to understand.

You open a form like this:
Form1.Show.

What sort of sessions do you have too many of?
0
 
MattiCommented:
Hi!

I'm not sure is this about some loaded form which prevent your app closing, then you see many open programs in taskmanagers screen, try this on Form_Unload event:

Public Sub UnloadAllForms()
   Dim Form As Form
   For Each Form In Forms
      Unload Form
      Set Form = Nothing
   Next Form
End Sub

Matti
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
untardedCommented:
Are you creating instances of the forms.  To guarantee that your forms are being handled you should create and destroy the instances of your forms.

rather than setting the show property of a form such as

 form1.show

create an instance of the form

'declare and create an instance of Form1
Dim oForm1 as Form1
Set oForm1 = New Form1
'show the instance
oForm1.Show
'when you are finished with your form
Unload oForm1
Set oForm1 = nothing


This will give you better control of how many forms are in memory at a given time. You can unload the forms individually or loop through them with Matti's example above.
0
 
MonNerdAuthor Commented:
I am doing all of the above..Sometimes it even loads other forms without having to open it up. why???Oh why???
0
 
MattiCommented:
Hi!

When something on a different form is caled, it causes automaticly load that form.
For example Set Picture1.Picture = Form2.Picture1.Picture
Is there form names like this in Your code?

Matti
0
 
untardedCommented:
Can you post your code?
0
 
MonNerdAuthor Commented:
Its a huge application. Which part of the code would you like to see...

Matti,

The Picture1.picture is not there...Thanks
0
 
MattiCommented:
Hi!

It could be difficult , that was a sample from the kind of cause you could have there.

Have you tried the code in my first post?

Put line "UnloadAllForms" on main forms Form_Unload event.

Does it stop the problem behavior?

Matti
0
 
MonNerdAuthor Commented:
Yup... Already has the code....
0
 
MonNerdAuthor Commented:
Guess what... The code checks to see whether form is empty or not using the Isempty function. If its not empty then it does not close the form... This code has been written by someone else... So what now...
0
 
MonNerdAuthor Commented:
Hi Matti,
On the main id I do have the Unload all forms... but what if I've to reopen a  form again & again & again without having to close the main, the form shows as open as many times as you open. Closing a form does not seem to do anything.

Have I confused you enough?? Ha!Ha!
0
 
MattiCommented:
When you exit the main form you need to close and run that UnloadAllForms code.

Do you have code in these events of those forms:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Private Sub Form_Unload(Cancel As Integer)

What kind of code?
That could prevent program ending normally.


Matti




0
 
MonNerdAuthor Commented:
All the forms have code in their event unload but not queryunload..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.