[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

Unloading a form

this is all the points i have.... i have a form. when it unloads it misteriously reapers. how do i keep this form happening. why does the form show up after it reloads. is this because there is an event from the form taht is staill in effect?
0
hess
Asked:
hess
  • 6
  • 3
  • 3
  • +4
1 Solution
 
crazymanCommented:
Post the code you are using to close the form and any code in the form load
0
 
vgruCommented:
The reason the form keeps reappearing is that you must be calling a method or function in that form from another form.

Any reference you make to any control or procedure in that form from another form will re-load the form after you unload it.
0
 
mcriderCommented:
hess,

Vgru's answer is not complete, and doesn't solve your problem...

You CAN call a procedure in your form and not have it display.  What you have to be careful about is that in the procedures that you call, you don't show the form.

Also, any time you call a procedure on a form and the form is not currently loaded, the FORM_LOAD event will fire...
If you have a Form.Show or a Me.Show in the FORM_LOAD event, then the form will be displayed, even though you didn't intend to have the form display...

Also remember, when you are ending your program, do this:

Dim X As Object
For Each X In Forms
    Unload X
Next

Hope this helps!


Cheers!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
caraf_gCommented:
And I'll add to that....

Unload Form1 '<Form1 is unloaded here... but...

Form1.Show ' - this creates a new instance of Form1. And Form1 is reloaded.
or
Form1.SomeControl.SomeProperty = SomeValue ' - this also creates a new instance of Form 1

but
Call Form1.SomeSub(SomeParameters) 'is fine, as long as inside SomeSub you don't refer to properties of Form1 or one of its controls.
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>but
Call Form1.SomeSub(SomeParameters) 'is fine, as long as inside SomeSub you don't refer to properties of Form1 or one of its controls.<<

If this is the case, this sub have nothing to do there!!!
0
 
caraf_gCommented:
Ah, very true, but that is a different issue altogether ;-)
0
 
caraf_gCommented:
Hm... on the other hand though, the sub may be manipulating module level variables of the Form1 module.

<playing devil's advocate>
0
 
Éric MoreauSenior .Net ConsultantCommented:
Module level variables becomes Form's properties.
0
 
caraf_gCommented:
DOH!

Of course....

I'll modify my statement:

Whenever you refer to anything to do with Form1, the "object" Form1 is instantiated. But only if you refer to window or control properties of Form1, a window is created for Form1.
0
 
caraf_gCommented:
To illustrate this, create a project with two forms, form1 and form2. Stick a command button on form1.

Paste the following code in form2:
Option Explicit
Public SomePublicVariable As String
Private Sub Form_Initialize()

MsgBox "I'm instantiated"

End Sub

Private Sub Form_Load()

MsgBox "I'm loaded"

End Sub



Paste the following code in Form1
Option Explicit

Private Sub Command1_Click()

MsgBox "Set a public variable on form2 but don't touch any window properties"
Form2.SomePublicVariable = "hi"

MsgBox "Set a window properties on form2"
Form2.Caption = "hi too"

End Sub

0
 
hessAuthor Commented:
I"m here but i just woke up and have to go to work. thank you for all of your input. i'll try this code out tonight. thankyou.

Jon
0
 
AndySulzCommented:
put End in the Form_Unload ()
0
 
hessAuthor Commented:
I have multiple forms. i dont' want to end the application
0
 
Éric MoreauSenior .Net ConsultantCommented:
On december 22, you said that you were to try the code.

So where are you now?
0
 
AndySulzCommented:
do a form.visible = false in it then
0
 
caraf_gCommented:
That way you'll end up with loads of forms loaded in memory but not visible. A really bad suggestion.
0
 
mcriderCommented:
Hess,

Did you try my original solution adding the following to the FORM_UNLOAD event:

Dim X As Object
For Each X In Forms
    Unload X
Next


Cheers!
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now