Link to home
Start Free TrialLog in
Avatar of KentDBerry
KentDBerry

asked on

ObjectDisposedException error

On my main form, I have a menu item that calls the below code.  In the Sub New() of the form, I call a login form that determines permissions of user on that form.  However, if the user presses the cancel button on the login form, the login form will close and so will the below frm.  And I get an  ObjectDisposedException error on the line fmr.ShowDialog().  (i.e. Cannot access a disposed object).

What do I need to to do to work around this errror.  I was hoping the Try Catch statement would trap the error but it does not.
Private Sub UserMaintenanceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UserMaintenanceToolStripMenuItem.Click
        Try
            Dim frm As frmUsersMaintenance = New frmUsersMaintenance
            frm.ShowDialog()
        Catch ex As Exception
        End Try
 
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zer0_ring
zer0_ring

Are you disposing the form that this menu item is part of?
It seems to me that you may need to work out your events esp. if your calling form Close event before doing other things.
Avatar of KentDBerry

ASKER

Thanks.