
Error when showing form: Object reference not set to an instance of an object
By the way:
This is a Windows application project, and I'm using MS Development Environment 2002 Version 7.0.9466 and MS .Net Framework v. 1.0.3705.
Hans.
Hi,
I have a form1 which is the main startup form of my project. On this form I have a button1 that activates a timer. When this timer fires, it runs a sub that calls a sub in another form (form2). This all works fine. On form1 I also have another button, button2. This button2 runs form2 (with the code oForm2.ShowDialog()). This also works just fine UNLESS button1 has already previously caused a call to the sub on Form2 (still with me?) - in which case I get the above error.
I have tried declaring a public variable to hold form2 in the load of form1, like:
"Dim oForm2 As New frmForm2()"
Right under the "Inherits System.Windows.Forms.Form" under the "Public Class frmForm1" statement in form1. When I issue oForm2.ShowDialog(), I get the error. I have also tried "Public oForm2 as New frmForm2() in the same place - same result. I have also, in the click event of button2, declared a new oNewForm2 as new frmForm2() and done oNewForm2.ShowDialog(). Same problem. I have also tried only declaring the variables to hold the form2 reference in the subs themselves. Same problem.
So the problem is: After button1 causes a call to a sub on form2 (and it can do this again and again with no problems) then it is not possible to show the form2 from another sub without getting the error. I hope this is understandable.
Any ideas what is causing this?
Thanks,
Hans