Results 1 to 6 of 6

Thread: [RESOLVED] Cancel Close of MDI child forms.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Resolved [RESOLVED] Cancel Close of MDI child forms.

    Hi all,

    I have an application using a multiple document interface.
    Attached is a very basic shell of one that will highlight my problem.
    If I press the close button on the main MDI form I set a messagebox to appear asking if the user want's to save contents of each form or cancel the close.

    Can anyone suggest a way to stop the loop so that if the user presses cancel on any of the message boxes it will cancel the close operation alltogether?
    Attached Files Attached Files

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Cancel Close of MDI child forms.

    Try this.... Get a count of the forms before you ask them to unload. Then compare against the count after the unload call. If they are the same, then the user chose not to close:
    Code:
        Dim nrForms As Long
        Dim chkme As Long
        nrForms = Forms.Count
        ' loop thru them from last to first, so your mdi isn't counted
        For chkme = Forms.Count - 1 To 1 Step -1
            Unload Forms.Item(chkme)
            If nrForms = Forms.Count Then
              Cancel = True
              Exit For
            Else
                nrForms = nrForms - 1
            End If
        Next chkme
    Last edited by LaVolpe; Nov 7th, 2008 at 12:25 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Cancel Close of MDI child forms.

    Works a charm!! thankyou

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Cancel Close of MDI child forms.

    Actually, not quite...
    Because you count backwards it doesn't start with the active form. So the messagebox that appears doesn't relate to the child form that is on top in the MDI form.
    As they close I'd like the form that is closing to be visible.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Cancel Close of MDI child forms.

    I'd like to unload the active form first then display the other forms confirmation is required to close them. Any ideas on how this is done?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Cancel Close of MDI child forms.

    Worked it out.

    I just needed to change
    Unload Forms.Item(chkme)
    to
    Unload MDI.ActiveForm

    Thanks heaps for your help there La Volpe!

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