Search Tools Links Login

Is Form Loaded check without causing form to load (EASY!)

Check to see if a form is loaded without actually loading the form, or access public form variables without causing the form to load

Original Author: Dave Gallant


Ever want to check to see if a form is loaded before you try to access it?

The only way I know of (other than this way) is to loop through the form collection...
a rather large pain in the rear.

The trick is to create a new form property.

Add the following code to any form:

  Option Explicit


  ' Create a new property variable

  As Boolean

  ' get the value of the new property

  Public Property Get
  As Boolean


Loaded = m_bLoaded

End Property

' set the value of the new property

  Public Property Let
  bLoaded As Boolean)


m_bLoaded = bLoaded

End Property

  Private Sub


' set the loaded property to true

   Me.Loaded = True

End Sub

Private Sub Form_Unload(Cancel
  As Integer)


' set the loaded property to false

   Me.Loaded = False

End Sub


Now, form any other form or module, you can do this (assume you are using the
default form name)

If Form1.Loaded = True Then

MsgBox "Form is loaded"


MsgBox "Form is not loaded"

End If

Accessing this property will not cause the form to load in the event that loaded
is false.

However, if you make a single variable and make it public on the form, and try
to access it, the form will load.

You can actually use this property method to retain any data and access it without
reloading hte form.

I created a custom input box field in which the "Return String" is
a custom property, like the loaded property.

then I just do this: 1, me ' (show my new form

  strInput = Form1.strInput '(this
  will not cause the form to reload provided your property is called strInput!)

give it a shot, let me know if you have any problems.

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 100 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.