Accessing form from module

G

Guest

dear sir

In my vb.net window application i have the MDI form MainMDI and child form form1 adn module as MainModule
In my MainMDI Parent form i have one toolbar i.e. tbraction. I am trying to show the toolbar when i am displaying form1 (child form) . when i close the child form i want it to be hiddeni.e. invisible

i wrote the code in MainModule as

Friend Module MainModule

Friend frmMDI As MainMDI

End Module

and in the child form closed event i wrote:


Private Sub form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
On Error GoTo errHandler

frmMDI.tbrAction.Visible = False
Exit Sub

errHandler:
If Err.Number <> 0 Then
MsgBox(Err.Number & vbCrLf & Err.Description)
End If


but while accessing the code it give me error

Error 91
Object reference not set to an instance of the object


Please let me know how to solve this error.


thanks
Mustafa
 
G

Guest

Mustafa,

Which object is throwing that error?

if it's Friend frmMDI As MainMDI then you need to set it to something.

Friend frmMDI As New MainMDI?

I'm not too sure since I never liked using modules, but too all their own. You might need to take time in examining it.

Lastly, I see On Error GoTo.. That made my skin crawl.

Try
' code
Catch exp As Exception
System.Diagnostics.Debug.WriteLine(exp.ToString)
MsgBox(exp.ToString)
End Try

^ that's better means of error handling.
 

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

Top