Results 1 to 4 of 4

Thread: Query Unload

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    187

    Query Unload

    Hi all,

    I have the following code in the QueryUnload procedure of a form:

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu then
    CleanUp 'procedure to unload all forms & clean up db connections
    Unload Me
    Set Form1 = Nothing
    End If
    End Sub

    In CleanUp the code is:

    Public Sub CleanUp()
    Dim FormX As Form

    For Each FormX In Forms
    Unload FormX
    Set FormX = Nothing
    Next FormX

    'additional code to clean up the db connections
    End Sub

    My question is, are the last 2 lines in the Query Unload procdure ie.

    Unload Me
    Set Form1 = nothing

    neccessary since the CleanUp procedure unloads all forms and set them to nothing ?

    I read somewhere that it was and just wanted to confirm if it was true.

    Cheers

    Jack

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    No
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    The "Unload Me" part is redundant, because you are already in the QueryUnload event. The form is already being unloaded.

    The "Set Form1 = Nothing" part is only necessary if you want the Terminate event to be triggered. Next to triggering the Terminate event, it cleans up the implicitly declared Form1 variable. If you don't do it, VB will do it for you, but many people do not rely on VB to do it correctly, so you can leave it in if you like.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    187
    Many thanks for your responses. It has cleared this issue up for me.

    Jack

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