Results 1 to 8 of 8

Thread: Unload Forms Properly

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    32
    I am having problems unloading forms. I am currently running a parent form with several child forms and a few seperate forms. In the Form_Unload of the parent form, I am running the following block of code:

    Private Sub Form_Unload(Cancel as Integer)
    Dim frm as Form

    For Each frm in Forms
    Unload frm
    Next frm
    End Sub

    When this is run, it makes it all the way through, then after the End Sub is executed, i get an illegal operation error.

    VB5 caused an invalid page fault in
    module KERNEL32.DLL at 014f:bff7926e.

    I have been trying to get this thing to work now for several hours, and am out of things to try. Anyone have any suggestions?????

  2. #2
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    It's only a guess but, you are looping through all the forms and unloading them, so therefore is it trying to unload the mdi parent form again.
    Try something like :

    for each frm in forms
    if frm.name <> "mdiParent" then unload frm
    next frm

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    32
    Thank you for your help, but I still got the same error. Anyone else have anything I can try?

  4. #4
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73
    Hello,
    Here we go try this, I've never had no problems with it so hopefully you shouldn't either.
    Code:
        Dim x As Integer
        For x = (Forms.Count - 1) To 0 Step -1
            If TypeOf Forms(x) Is MDIForm Then
                '//DO NOTHING
            Else
                Unload Forms(x)
            End If
        Next x
    Hope it helps,
    Desire.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    32
    Still no luck Desire. Thanks anyways. Can anyone else offer an opinion?

  6. #6
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73
    Hello,
    Is your parent form a MDIForm of just a standard form?

    Desire.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    VB5 caused an invalid page fault in
    module KERNEL32.DLL at 014f:bff7926e.
    I have had the same kind of problem once, but I need to take a look at your project. Could you send it to me?

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    32
    Thank you for all of your help. I have actually found the problem, but would like some input on this as well.

    The problem was that I was Redimming a few arrays several times throughout the code. When it went to unload the form, I guess it had problems with releasing this memory. I got around it by:

    Set Array = Nothing

    Then I went on with:
    For Each frm in Forms
    Unload frm
    Next frm

    That worked great. I do not fully understand why it would have had a problem releasing those arrays. Could anyone comment on that?

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