Just use the objRef.Close method where objRef holds a reference to the instance of the form to be closed. If it is the startup form, the entire application will close.
Hi,
I am getting an object reference error when I tried the following code:
In Form 2:
dim refForm1 as Form1
refForm1.Close
If I do this
dim refForm1 as new Form1
refForm1.Close
I don't get an error, but that's a new object so it won't close the form I wanted to.
Now I am opening Form2 from Form1, is that going to be a problem closing the Form1?
Where is the varaiable holding the reference to the form you created? That is the variable you must use to Close the instance of the form.
If you are working on a project that was upgraded from VB6 by the VB.Net Upgrade Wizard, then you get the reference from the Shared method formname.DefInstance, I think. I got rid of all that code after changing my code to explicitly create each instance of the form and use an object variable to hold the reference.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.