VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



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

by Dave Gallant (1 Submission)
Category: Miscellaneous
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (13 Votes)

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

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



 

 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

  Dim m_bLoaded 
  As Boolean

  ' get the value of the new property

  Public Property Get Loaded() 
  As Boolean


 
 
  

 Loaded = m_bLoaded


 

 

 End Property


 

 ' set the value of the new property

  Public Property Let Loaded(ByVal 
  bLoaded As Boolean)


 
 
  

 m_bLoaded = bLoaded


 

 

 End Property


 



  Private Sub Form_Load()


 
 
  

 ' 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"



 Else



 

 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:



 

 Form1.show 1, me ' (show my new form 
  modal)

  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.

Download this snippet    Add to My Saved Code

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

No comments have been posted about Is Form Loaded check without causing form to load (EASY). Why not be the first to post a comment about Is Form Loaded check without causing form to load (EASY).

Post your comment

Subject:
Message:
0/1000 characters