By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Speed tip: Set RowSource of Subform's Combo box in GotFocus event rather than Enter

P: n/a
Hello all,

I just discovered something (stop me if you've heard this before....) that
was causing me a significant performance hit when opening a form with
subforms.

To speed up loading the form, I set the rowsources of its, and its
subforms', combo boxes in the "Enter" events of the combo boxes. That's the
standard trick for not loading the rowsource unless/until the user actually
needs the combo box. For example:

If Me!cboInitial.RowSource = "" Then _
Me!cboInitial.RowSource = Me!txtPrefix & "refCarInitials" ... or
some query

I also set the subforms' SourceObjects, LinkChildFields, and RecordSource in
the Load event of the main form.

What I discovered is that setting the SourceObject, etc fires off the Enter
event of the combo boxes in the subforms. In fact, even if you don't set
these properties in the code, but instead have them predefined, Access will
"Enter" the combo boxes of the subforms when opening up the main form. So
the RowSources of those combo boxes get run way before the user has a chance
to click on them. This defeats the aim of speeding up form loading by
avoiding filling those RowSources until needed.

The solution was simple enough - move the RowSource code to the GotFocus
event of the combo boxes, which does not get fired by the main form opening.

Note that for combo boxes on the main form, it doesn't matter, as they
aren't "entered" when the main form is opened. It's the main form's act of
"setting up" its subforms that causes Access to enter the subforms' combo
boxes. You can test this be putting breakpoints or messageboxes in the
"Enter" events of the combo boxes.

Thought this might help someone. BTW, I got the inspiration for the
solution from an old post I read from someone (was it David Fenton?) who
said he couldn't remember why he always put the RowSource code in the
GotFocus event rather than the Enter event. Maybe this was why?

Regards,
Krisa

Nov 12 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.