ON load or on open (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 12:17
Joined
Dec 1, 2014
Messages
401
WHich event is best to use for the following.

Many of my forms are similar so i have created one form with variable defined within the form and these defined variablews will alter cpations etc when the form is first opened.

WHat is the best event to put this in. FOrm on open or on load? Or another event?

COde is
Code:
Me.Form.Caption = "Add " & StrTier1
Me.Lbl_Tier1Heading.Caption = StrTier1
Me.Lbl_NewTier1.Caption = "Please enter the new " & StrTier11 & " name:"
Me.Lbl_ConfirmTier1.Caption = "Please re-enter the new " & StrTier11 & " name:"
Me.Cmd_Add.Caption = "Add " & StrTier1
 

isladogs

MVP / VIP
Local time
Today, 12:17
Joined
Jan 14, 2017
Messages
18,211
You can't use Form open as the form isn't in memory until that has completed.

Form load follows after the form has opened and is ideal for the code you gave.

CAVEATS:
If for any reason the form settings change when changing records, you can use form current event.

Finally if for any reason the form stays open but becomes inactive for any reason, you can use the form activate event.
 

jleach

Registered User.
Local time
Today, 07:17
Joined
Jan 4, 2012
Messages
308
Generally speaking, I look at it like this:

The Open event's primary use is to validate the form is allowed to open, and cancel out if not.

The Load event should be used to more or less initialize the form, as at that point we've already verified that it is able to be opened.

Thus I agree with Colin: use the Load event for these.
 

missinglinq

AWF VIP
Local time
Today, 07:17
Joined
Jun 20, 2003
Messages
6,423
Actually, the Form_Open event is designed for doing what the OP describes, here, setting design components of the Form.

Form_Load would only needed, for this kind of thing, if there is a need to access the Form's data, which isn't available, as Colin suggested, until this event.

The question, here, I would think, is where/how, exactly the variable StrTier1 is set; is it derived from an OpenArg that is passed to the Form, when opening it...or is it derived from data within the Form?

In the former case, Form_Open should work...in the latter, Form_Load.

Of course, the simplest thing would be for the OP to try the code out in each event and look at the results! I mean, how much time would that involve?

Linq ;0)>
 

isladogs

MVP / VIP
Local time
Today, 12:17
Joined
Jan 14, 2017
Messages
18,211
Hi linq

Whilst I agree with everything you said, using Form_Open runs the risk that setting caption code etc may not work.
Whereas Form_Load will always work.

Personally I tend to restrict Form_Open code to the following types of action which affects the form as a whole:
- ReSizeForm Me
- DoCmd.Maximize
 

Users who are viewing this thread

Top Bottom