inside form2, when the exit button is clicked, it will call
formMain's exitApp()

Form2's Code:

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuFileExit.Click
Dim formMain1 As frmMain
formMain1.exitApp()
End Sub


FormMain1's Code:

Public Sub exitApp()
Dim dlg As DialogResult
dlg = MessageBox.Show("Exit?")
If dlg = DialogResult.Yes Then
Me.Close()
End If
End Sub


However the error given is:

Object reference not set to an instance of an object!