473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Form.Close

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
6 1861
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
"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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field...
1
by: Jules Winfield | last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
2
by: Chien Lau | last post by:
Hi, At a certain point in my application, I have access to a Form object. I want to close that form: form.Close(); There are any number of reasons why this form might not close. A common...
6
by: nadeem_far | last post by:
Hello All, I am working on a .Net desktop application and I am having problem displaying a form. I am using C# and version 1.1 of the framework. here is how the code looks likes and I will...
6
by: Tom | last post by:
Is there ANY easy way to close a MDI Child form in the middle of it's load? For instance, during the Load event I find a need to close the form (for whatever reason - maybe the user isn't ready for...
5
by: AP | last post by:
IS there a way to run a procedure if the users close access directly rather than closing a menu screen that I have built? There is an event that works on close for this form, but it doesnt seem to...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
7
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.