?
Solved

Form_Load

Posted on 2002-05-08
12
Medium Priority
?
211 Views
Last Modified: 2010-05-02
We have a VB application that runs all the time in the background (effectively as a service). However, it does contain a form that is only used in another mode (the program can run in a manual mode). It therefore contains a Form_Load function. Under what circumstances can Form_Load be called? I know, for example, that Form_Unload gets called if a user logs off from Windows.

Does anyone know all events that might cause Form_Load to be called?

0
Comment
Question by:simonslr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6995937
Form_Load event only fired once when a form is loading. What i would suggest is make the codes in Form_Load event as a Sub then call it like this:

Private Sub Form_Load()
    Call mySub
End Sub

Private Sub mySub()
//Do the stuff here
End Sub

'You can put the Sub in a Module by change 'Private' to 'Public so that it can be called by another forms
0
 

Expert Comment

by:HeN_da_MaN
ID: 6995947
You could use Form_Activate, I don't know what U want to do.
Form_Load gets called whenever you call a function in the codemodule and your form is not active.
You could also call Form.Show to call Form_Load (this works only one time until you Unload the form again)
Maybe I am able to help you if you give more info.

Hen
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6995948
To be more clear on my comment, create a Sub so that we can remember the specific name of the function to call (rather than Form_Load). Of course you still can Call Form_Load within your form, like this:

Private Sub Command1_Click()
    Form_Load
End Sub

Private Sub Form_Load()
    MsgBox "Hello World"
End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Expert Comment

by:TimCottee
ID: 6995955
Well there are basically three ways to call the form_load procedure code:

1) Load the form; Load frmMyForm
2) Call it explicitly (requires that the form is already loaded and is being called from a procedure within the form's scope); Call Form_Load()
3) Reference a public method or object in the form; this is a tricky one as if you have not yet explicitly loaded a form, any direct reference to an object or method of the form will cause it to be implicitly loaded. For example if you have a textbox on the form called text1 then any reference in any other part of the project such as frmMyForm.Text1.Text = "Hello" will actually cause the form to be loaded (if it isn't already) and the Form_Load event code will be executed.

From what you say (and what you don't) my assumption is that because you have seen the form_unload code running when the application shuts down as a result of windows shutting down then you wonder how the form was ever opened. My suggestion is that this is caused by 3) above and that somewhere in your code you are referencing an object or method in that form which is causing it to be implicitly loaded but never shown.
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6995964
Bravo Super Tim !!!!
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 6996005
Hi Tim just a remark
*********************
Reference a public method or object in the form; this is a tricky one as if you have not yet explicitly
loaded a form, any direct reference to an object or method of the form will cause it to be implicitly loaded
*********************
calling a public method in a form that is not loaded will NOT load the form
but the form object will be initialized
and thus its initialize event will be called
and on ending the program its terminate event will be called
but if you reference any of the VISIBLE propertys of the form it will be loaded
say you set its caption or a control in it, then it will be loaded
0
 

Expert Comment

by:ngomte
ID: 6996051
Form Load is called whenever a refereence is made to a object to this form, other then the property procedure.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6996175
pierrecampe> if you reference any of the VISIBLE propertys of the form it will be loaded
or maybe we can say "if you reference any of the *built-in* properties"

     MsgBox Form2.Tag    ' this will load Form2
     
     MsgBox Form2.uhoh   ' this will not load Form2
0
 

Author Comment

by:simonslr
ID: 6996182
I don't think I've made my question very clear. I know that the Form_Load function is being called at start-up - we hide the form when running in non-manual mode ...

... but are there any circumstances that might cause Form_Load to be called again (for example in the same way that form_unload is called when a user logs off - in our case the program carries on running even when a user logs off).
0
 

Author Comment

by:simonslr
ID: 6996183
I don't think I've made my question very clear. I know that the Form_Load function is being called at start-up - we hide the form when running in non-manual mode ...

... but are there any circumstances that might cause Form_Load to be called again (for example in the same way that form_unload is called when a user logs off - in our case the program carries on running even when a user logs off).
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 150 total points
ID: 6996245
It should never be called again if it hasn't been unloaded. Unless called explicitly for some reason.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6996261
>are there any circumstances that might cause Form_Load
Without calling it in your code or referencing something on Form, no.
Are you sure there is an extra Form_Load executed?

>program carries on running even when a user logs off

Program can run without any form loaded.
Program can run without reexecuting Form_Load - e.g. form didn't unload for some reason:
- timer was active, some form code is stuck in a loop, circular references, noone called Unload in code, or someone called Unload, but that was cancelled in QueryUnload or Unload event....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question