Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Cannot access a disposed object. Object name: 'fm_repInitProjRequest'.
 

Cannot access a disposed object. Object name: 'fm_repInitProjRequest'.

I have a form lets call form0 that has 5 menu options up top and nothing more (roughly) like so:

Go to form1Go to form2Go to form3Go to form4Go to main menu

Clicking on any of the 'go to' forms, opens the form below the menu bar within form0. So form0 can 'contain' forms1-4.

Clicking on 'go to form4' produces a report.

The report is dependent on data entered on form2 or form3. I want to set up the option to press a button while viewing form2 or form3 so that form4 would open. This would make the need for 'go to form4' pointless as a menu option if you already have a button to press on forms 2 and 3.

So I tried to do that but I get an error.

I press the button on form2 or 3 and form4 does not open because I get a 'cannot access a disposed object. object name: 'fm_repInitProjRequest' <--the name of form4.

The original setup has the access to all forms1-4 in the form0 code behind, treating form0 as the mdiparent (i think).

I tried different things such as making form2 or 3 the parent or form0 but always get an error. This is the furthest along I got. How can I get form4 to load after pressing a button to launch it from forms 2 or 3?

ALEKS A  Wednesday, October 15, 2008 2:26 PM

Hello Bruce,

Thank you for responding.

I figured out a solution but its not quite what I would prefer.

In the code behind for form3 (which could be applied to form2 as well) I have this event procedure that runs when Iclick the View Project Document button:

Private Sub ViewProjDocWindow(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewProjDoc.Click

If (fm_main.param > 0) Then

fm_repInitProjRequest.WindowState = FormWindowState.Normal

fm_repInitProjRequest.ShowDialog()

fm_repInitProjRequest.BringToFront()

fm_repInitProjRequest.Refresh()

Me.Text = "Project Initiation Request"

Else

MsgBox("You must select a saved Project Initation record first")

End If

End Sub

First, the subroutine confirms that I am accessing a saved document before a report can be generated. If so, it passes that ID as a parameter to the report. If no parameter exists, then no saved document is being accessed. Therefore, don't load 'form4' and give a reason why.

fm_repInitProjRequest is the name for my 'form4'. I wanted to treat it as an MDI child so that I may toggle back/forth between the open forms but it does not let me. Instead I open this dialog box version of the form and the limitation is that I must close it when I am done.

I would prefer to have the flexibility to go back/forth between open forms rather than be forced to access only form4 until I close it.

-Alex A

ALEKS A  Monday, October 20, 2008 5:21 PM

Hi Alex A..,

The error description you provided indicates that you are attempting to access a disposed object. I don’t know how you create your Form4 object and how to pass the data to form4 form form2 or form3. So perhaps some code about this may help me to troubleshoot the problem.

Best Regards,

Bruce Zhou

Bruce.Zhou  Monday, October 20, 2008 5:33 AM

Hello Bruce,

Thank you for responding.

I figured out a solution but its not quite what I would prefer.

In the code behind for form3 (which could be applied to form2 as well) I have this event procedure that runs when Iclick the View Project Document button:

Private Sub ViewProjDocWindow(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewProjDoc.Click

If (fm_main.param > 0) Then

fm_repInitProjRequest.WindowState = FormWindowState.Normal

fm_repInitProjRequest.ShowDialog()

fm_repInitProjRequest.BringToFront()

fm_repInitProjRequest.Refresh()

Me.Text = "Project Initiation Request"

Else

MsgBox("You must select a saved Project Initation record first")

End If

End Sub

First, the subroutine confirms that I am accessing a saved document before a report can be generated. If so, it passes that ID as a parameter to the report. If no parameter exists, then no saved document is being accessed. Therefore, don't load 'form4' and give a reason why.

fm_repInitProjRequest is the name for my 'form4'. I wanted to treat it as an MDI child so that I may toggle back/forth between the open forms but it does not let me. Instead I open this dialog box version of the form and the limitation is that I must close it when I am done.

I would prefer to have the flexibility to go back/forth between open forms rather than be forced to access only form4 until I close it.

-Alex A

ALEKS A  Monday, October 20, 2008 5:21 PM

Glad to hear you have solved your problem, and thanks for sharing your solution.

Best Regards,

Bruce Zhou

Bruce.Zhou  Monday, October 20, 2008 5:36 PM

You can use google to search for other answers

Custom Search

More Threads

• Simpler example of SmartClient web service file retrieval than AppraisalWorkbench?
• Remote Server Issues
• Disable Auto-update?
• Export to excel in window forms using c#.net
• I want a ITXCO10.dll in WIN NT.
• Web Based Windows Application
• c#?
• Extensive Debug environment in new Terrarium?
• Cannot find "file:///D://.....". Make sure the path or the internet address is correct.
• Stats are not updating on my server