Form.Close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have made 3 forms lets say form1 and form2 and form3 now their is a button
on form1 that opens form2 and a button on form2 that opens form3,

I want to place a button on form3 that closes form2 but i use the code:
dim form2 as form2
form2.close

which you would think would work, but it returns with a error:

"An unhandled exception of type 'System.NullReferenceException' occurred in
Blank.exe

Additional information: Object reference not set to an instance of an object."

Please help
 
Hi,

The reason it's not working this way is because Form3 is a
child of Form2.

You can declare and instantiate your forms in a module.
This ensures that all the forms are visible to each other,
and you'll then be able to close Form2 from Form3.

HTH
-Mendhak
[MVP - VB]

-----Original Message-----
i have made 3 forms lets say form1 and form2 and form3 now their is a button
on form1 that opens form2 and a button on form2 that opens form3,

I want to place a button on form3 that closes form2 but i use the code:
dim form2 as form2
form2.close

which you would think would work, but it returns with a error:

"An unhandled exception of type
'System.NullReferenceException' occurred in
 
SimAda00 said:
i have made 3 forms lets say form1 and form2 and form3 now their is a
button
on form1 that opens form2 and a button on form2 that opens form3,

I want to place a button on form3 that closes form2 but i use the
code: dim form2 as form2
form2.close

which you would think would work, but it returns with a error:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Blank.exe

Additional information: Object reference not set to an instance of an
object."

Please help


Pass the reference to Form2 to Form3, then you can access it in Form3.

Armin
 
Armin,
Pass the reference to Form2 to Form3, then you can access it in Form3.
Are you sure.

When it is opened in the way as I normally do,
\\\
dim frm2 as new form2
frm2.show
frm3.owner = me
///

Than this goes in my opinion wrong if you close in form3 the owner (the
parent of the child)

(Not tested by the way)

:-)

Cor
 
Cor Ligthert said:
Armin,

Are you sure.

When it is opened in the way as I normally do,
\\\
dim frm2 as new form2
frm2.show
frm3.owner = me
///

Than this goes in my opinion wrong if you close in form3 the owner
(the parent of the child)

(Not tested by the way)

:-)

Cor

He also didn't mention whether Form3 is shown modally. There are other
design questions (e.g. raise event instead?), too. Without knowing the
circumstances, there can't be a more sophisticated answer, but it works in a
"technical" way. :-) (OT: That's BTW one of the reasons why I didn't
respond to the group anymore. The answer is often like "if..then,
elseif..then, elseif..then", and this takes a lot of time.)

Armin
 
Armin,
He also didn't mention whether Form3 is shown modally. There are other
design questions (e.g. raise event instead?), too. Without knowing the
circumstances, there can't be a more sophisticated answer, but it works in
a
"technical" way. :-)

I wrote my message to let you make the addition above.

:-)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top