Ask the Form Itself Whether it’s Loaded

Ask the Form Itself Whether it’s Loaded

Occasionally you initialize a form but don’t load it. You might do this to read in initial application Registry values. After that, any references to control properties on the form automatically cause your Form_Load event to fire, whether or not you intended to fire the Form_Load event. If you want to know programmatically whether your form has been loaded, implement these steps.
Add a private Boolean variable to your form and call it m_bLoaded:

 Option ExplicitDim m_bLoaded as Boolean

Add Property Let and Get procedures to provide public read and write access to your form’s internal m_bLoaded variable:

 Public Property Get Loaded() As Boolean	Loaded = m_bLoadedEnd PropertyPublic Property Get Let(ByVal bLoaded As Boolean)	m_bLoaded = bLoadedEnd Property

Add this line of code to your form’s Load event:

 Me.Loaded = True

To see whether your form is loaded from other modules or other forms, use this code:

 If  FormName.Loaded = True Then	' Do stuff that can only be done if the form 	' has been loaded (i.e., set control properties)EndIf

Using this code helps prevent you from accidentally firing the Form_Load event.

See also  Small Business Strategies with Venmo

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist