me.close closes both open forms

Posted on 2011-10-14
Last Modified: 2012-05-12
I have a form that is an mdichild of another form. from this form i open another form with showDialog() in this form i call me.close and it closes both itself and the formt hat i opened it from

can anybody explain why?? :o(
Question by:ict-torquilclark
    LVL 33

    Expert Comment

    I use the following function to open MDI forms. To call it I just use like this:

    Call OpenMDIForm(New frmCarsList(), Me)

    On the frmCarsList, I put this on the Close button click:

    Private Sub btnSairform_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSairform.Click
        End Sub

    And it just works fine for me.

    Public Sub OpenMDIForm(ByVal frmName As Form, ByVal frmParent As Form, Optional ByVal frmTag As Integer = 0, Optional ByVal frmDuplicates As Boolean = False)
            Dim IsLoaded As Boolean = False
            Dim frm As Form
            On Error Resume Next
            ' Case it doesn't allow duplicates
            If Not frmDuplicates Then
                ' Checks if the form is already opened
                For Each frm In frmParent.MdiChildren
                    If frm.Name = frmName.Name Then
                        IsLoaded = True
                        Exit For
                    End If
            End If
            ' Case it's not open
            If Not IsLoaded Then
                frmName.MdiParent = frmParent
                ' Put the value on the Tag of the new form
                If frmTag > 0 Then frmName.Tag = frmTag
            End If
            frmName = Nothing
            frm = Nothing
        End Sub

    Open in new window

    LVL 83

    Accepted Solution

    >i open another form with showDialog() in this form i call me.close and it closes both itself and the formt hat i opened it from

    You mean you call the me.Close on dialog form? Try setting the me.DialogResult

    Show us the code you are using to show the dialog.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now