-
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
-
-
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.
-
Many thanks for your responses. It has cleared this issue up for me.
Jack