By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,579 Members | 1,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,579 IT Pros & Developers. It's quick & easy.

Form.Close

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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 buttonon 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 inBlank.exe

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

Nov 21 '05 #2

P: n/a
"SimAda00" <Si******@discussions.microsoft.com> schrieb
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
Nov 21 '05 #3

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

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
Nov 21 '05 #4

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb
Armin,
I want to place a button on form3 that closes form2 but i use
the code: dim form2 as form2
form2.close

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


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

Nov 21 '05 #5

P: n/a
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
Nov 21 '05 #6

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb
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.

:-)


:-)

Armin
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.