Results 1 to 5 of 5

Thread: [RESOLVED] A Problem with MDI Parent and Close ( X ) Button..

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Resolved [RESOLVED] A Problem with MDI Parent and Close ( X ) Button..

    I have a MDI Parent form...

    Now .. for the close button ( X ) on top right i have the code

    vb Code:
    1. Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3.    
    4.   Dim vbResponse As VbMsgBoxResult
    5.   vbResponse = MsgBox("Are You Sure You want to exit the Program?", vbYesNo, " Exit Application")
    6.   Select Case vbResponse
    7.   Case vbYes
    8.   Unload Me
    9.   Case vbNo
    10.   Cancel = -1
    11.   End Select
    12.      
    13. End Sub

    as suggested by some1..

    and I have a EXIT coded in the menu.. the code is

    vb Code:
    1. Private Sub mnuexit_Click()
    2.  
    3. msg = MsgBox("Are You Sure You want to exit the Program?", vbYesNo, " Exit Application")
    4.  
    5. If msg = vbYes Then
    6. Unload Me
    7. Else
    8. Exit Sub
    9. End If
    10.  
    11.  
    12. End Sub

    Now the problem is.. that when i click on the close button.. its works fine..

    But when I click on the the EXIT MENU.. then it 1st runs its msgbox.. then runs the CLOSE BUTTON code??? I dont know why.. so the msgbox pop ups twice on the EXIT MENU

    Please help here.. I dont want the box to come twice asking again to exit or not..

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: A Problem with MDI Parent and Close ( X ) Button..

    Never done this, but I think you should make a code for the queryunload sub like

    if unloadmode = something then
    show messagebox etc.
    end if

    for 'something' you might want to range from 0 to 2
    Delete it. They just clutter threads anyway.

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: A Problem with MDI Parent and Close ( X ) Button..

    The only code you need in the "mnuexit_Click" event is:
    Unload Me

    This is because that statement will automatically fire the "MDIForm_QueryUnload" event.

    Furthermore, you do not need the "Unload Me" statement in the "MDIForm_QueryUnload" event. You can get rid of the whole Select Case statement, and code this If statement:
    If vbResponse = vbNo Then
    Cancel = 1
    End If
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: A Problem with MDI Parent and Close ( X ) Button..

    yeah i put the whole code in

    unloadmode = 0 .. it works..

    repped and resolved..

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: [RESOLVED] A Problem with MDI Parent and Close ( X ) Button..

    used.. BruceG idea.. works and looks much better

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width