Best place to set the Row Source for a combo-box in a form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

MS Access 2K, Windows XP
====================
Hi,

I have a form with a combo-box whose row source is a query. I want to give
the user an option to sort the data for the comb-box by two different
variables. To accomplish that, I have an Option Group/frame with 2 options,
and based on the selected value, I set the row source for the combo-box. The
Option Group/frame has a default value (to ensure that there will be a sort
criteria).

I've placed the code in the "On Enter" event of the combo-box, where I set
the row source for it based on the value of the Option Group/frame, and also
have a requery statement before I exit the On Enter event.

It is working fine, but I wanted to get a second opinion if possible, to
make sure that I am doing this the correct way.

Do I need to place the (same) code in any other event? Do I need to check
for any thing else, any errors etc.?

Will appreciate any feedback on this.

Thanks.

-Amit
 
I wouldn't use the OnEnter event since most of these requeries are going to
be superfluous and create overhead you probably don't need. You really only
need to run the code when the value of the Option Group changes so the code
actually belongs in the AfterUpdate event of the option group.

You may also need to initialize the recordsource of the combo via the Open
event of the form.
 
Write code in the before update or on enter event of the combo box that
sets the property of the combo box row source to one of two SQL
statements based on the value of the option box.

You are on the right track here, just use Sandra's suggestion to
initialize the combo recordsource AND also initialize the option box to
one choice or the other...

HTH, Tom
 
tlyczko said:
Write code in the before update or on enter event of the combo box that
sets the property of the combo box row source to one of two SQL
statements based on the value of the option box.

You are on the right track here, just use Sandra's suggestion to
initialize the combo recordsource AND also initialize the option box to
one choice or the other...

Hi Tom,

Thanks for the response. I'm not quite sure why I would need to place the
code in the Before Update or On Enter event of the combo-box, IF I already
have the code in the After Update of the Option Box, AND in the form On Open
event to initialize the Row Source?

-Amit
 
Thanks everyone, for your prompt responses :)
I initialized the row source in the On Open event of the form, and have code
in the After Update event of the Option Group.

Thanks again, and have a nice weekend.

-Amit
 
Back
Top