Load Event

See Also9SRK9N9              ExampleP0WSH3>Low

Applies To

Form14TJ2LN, MDI form1ILMZQ7.

Description

Occurs when a form is loaded.  For a startup form, occurs when an application starts, as the result of a LoadGU0759 statement, or as the result of a reference to an unloaded form's properties or controls.

Syntax

Sub Form_Load ( )

Sub MDIForm_Load ( )

Remarks

Typically, you use a Load event procedure to include initialization code for a formfor example, specifying default settings for controls, indicating contents to be loaded into combo boxes or list boxes, and initializing form-level variables.

In code, when you reference a property on an unloaded form, the form is automatically loaded, but is not automatically made visible unless the MDIChild property is True.  If an MDI form is not loaded, and a child form is loaded, both the MDI form and the child form are automatically loaded and both become visible.  Other forms are not shown until you either use the Show2IF9Z3Q method or set the Visible property to True.

The following code in an MDI form Load event automatically loads an MDI child form (assuming Form1 has its MDIChild property set to True):

Dim NewForm As New Form1

NewForm.Caption = "New Form"   ' Loads form by reference.

Since all child forms become visible when loaded, the Caption property reference loads the form and makes it visible.

 

Note   When you create procedures for related events, such as Activate2E06TW, GotFocus32EWUCC, Paint25UTDKO, and Resize2WM7WLP, be sure that their actions don't conflict and that they don't cause recursive events.

 


See Also

Help:

Load StatementGU0759

QueryUnload Event0HC58S7

Unload EventY083CJ

Unload Statement17FKE8Z

 

Programmer's Guide:

Chapter 14, "Multiple-Document Interface (MDI) Applications"


Load Event Example

The example loads items into a combo box when a form is loaded.  To try this example, paste the code into the Declarations section of a form that contains a combo box.  Then press F5.

Sub Form_Load ()

   Combo1.AddItem "Mozart"            ' Add items to list.

   Combo1.AddItem "Beethoven"

   Combo1.AddItem "Rock 'n Roll"

   Combo1.AddItem "Reggae"

   Combo1.ListIndex = 2               ' Set default selection.

End Sub