The Forms collection is composed of objects, each of which is a Form object.

When a form is opened and closed, these events take place in the sequence listed:

  1. Form_Initialize The form is an object created with no window or controls yet. A form can be created but not necessarily loaded by declaring a form object and then setting it to a particular form object. You can execute subs, functions, and property procedures added without forcing a load. A load will be forced with the Load method or if any built in properties or controls on the form are accessed. Code here can be used to initialize any variable pertaining to the particular form.
  2. Form_Load The form has been created, is loading itself and its control, has a window (including its window handle (hWnd) and device context (hDC). A form can be loaded but not necessarily shown. If the form is the Startup Object for the project, then it loads automatically. Accessing a control or built in member of form can also force the form to load.A load and activate can be forced with the Show method. Once loaded, a form can be shown or hidden without re-tripping the Load event. Some forms are loaded but never shown.
  3. Form_Resize. The form is sized.
  4. Form_Activate Each time a form is displayed or shown, the is event fires. To have code here execute only when loaded, toggle a Boolean variable during the Load event.
  5. Form_GotFocus. The form is finally there.
  6. Form_Paint Happens if anything needs to be painted on the form.
  7. Form_QueryUnload The last event before the Unload event. There is an opportunity here to cancel the unload and to learn why the unload occured. This event may not occur if the End statement is used or if the End button is used during development.
  8. Form_Unload The form has just returned to its created but not loaded state. The window and controls are gone. Note that the user interface is gone but not the code portion. To avoid funkiness Set frmX = Nothing.
  9. Form_Terminate After all memory an resources used by the form are released, this event fires before the form is destroyed.

Check if Form is loaded

This function returns whether a specified form is currently loaded or not.

Public Function FblnFormLoaded(strForm As String) As Boolean
    For lngCount = 0 To Forms.Count - 1
        If Forms(lngCoutn).Name = strForm Then
            FblnFormLoaded = True
            Exit Function
        End If
    Next lngCount
    FblnFormLoaded = False
End Function

Page Modified: (Hand noted: ) (Auto noted: )