Error when showing form: Object reference not set to an instance of an object 
Author Message
 Error when showing form: Object reference not set to an instance of an object

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



Mon, 25 Jul 2005 20:39:23 GMT  
 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



Mon, 25 Jul 2005 20:43:47 GMT  
 Error when showing form: Object reference not set to an instance of an object
I've had the same problem once. The de{*filter*} said the
problem lay in showing the forms, but when I make a try
catch statement, and printed the errordescription I
noticed that there were errors at other places.

Maybe do that..

try
  frm = new frm()
  frm.show()
catch ex as exception
  msgbox(ex.GetBaseException.ToString)
end try

something like that

Klaus



Mon, 25 Jul 2005 21:47:09 GMT  
 Error when showing form: Object reference not set to an instance of an object
Thanks Klaus - you're right. - The problem seems to be with sending e-mail
using MAPI. I'll start a new thread on it...



Quote:
> I've had the same problem once. The de{*filter*} said the
> problem lay in showing the forms, but when I make a try
> catch statement, and printed the errordescription I
> noticed that there were errors at other places.

> Maybe do that..

> try
>   frm = new frm()
>   frm.show()
> catch ex as exception
>   msgbox(ex.GetBaseException.ToString)
> end try

> something like that

> Klaus



Tue, 26 Jul 2005 00:20:31 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Multiple Forms Question: Object reference not set to an instance of an object

2. Please help with error: Object reference not set to an instance of an object

3. How to fix Error: Object reference not set to an instance of an object

4. Error: Object reference not set to an instance of an object

5. Object reference not set to an instance of an object

6. Object Reference Not Set to an Instance of an Object

7. Object reference not set to the instance of an object

8. Object reference not set to an instance of an object

9. Object reference not set to an instance of an object

10. Object reference not set to an instance of an object

11. New Twist on: Object reference not set to an instance of an object

12. Object reference not set to an instance of an object

 

 
Powered by phpBB® Forum Software