Form close and re-show problems.
Ok, I cannot open a particular form after it has already been loaded.
frmQ1.Show()
Me.Close
This is the code i use to close Q1. Then whe I try to re-show it again from frmMenu I get an error saying it cannot load the disposed object. What does that mean? I guess that it is because I closed it instead of hiding it. But when I hide it, I want it to activate the Form Load event again which I can't really do unlees I restart the form and I don't know how to do it. Any help appreciated.
Re: Form close and re-show problems.
Two things. One, when you defined the form frmQ1 you probably instanciated it with something like
"Public frmQ1 As New frmQ". When you .Dispose of the form by way of the .Close method, your
destroying the instance of frmQ1.
To fix that, yes, you just do a .Hide/.Show or create a new instance of it when you need to show it again, like I just coded. ;)
This will take care of #2 but if your always destroying/creating the same form then its better on resources and performance if you .Hide/.Show.
Now this brings up issue #2 again. To get around that, you need to re-code the load event so things happen differently
rather then relying on the load event.
Re: Form close and re-show problems.
Hi martw,
Whenever I open a form in a project, I use the following approach:
In this example, the name of my form is Window
VB Code:
' First declare the object
Dim objWindow as New Window
' Now insert the following after an event to open the form
If Not objWindow Is Nothing Then
If objWindow.Created = True Then
objWindow.Show()
objWindow.Activate()
Else
objWindow = New Window
objWindow.Show()
objWindow.Activate()
End If
End If
With this code, you can close forms or hide them; either way thay should open correctly.
NPath