[AccessD] Filtered combos

jwcolby jwcolby at colbyconsulting.com
Thu Mar 5 09:43:56 CST 2009


Oh, OK I see.

The way I normally work is that I have a clsCtlCbo.  That class is automatically loaded by the 
control scanner in clsFrm, so every combo on a form automatically gets a clsCtlCbo instance loaded 
as soon as the form loads.  Each clsCtlCbo instance will sink the events for the combo that it 
processes.

In clsCtlForm you add a pair of new variables to hold the current query, and the query that will 
load when the combo gets the focus.  In the event GotFocus / LostFocus sinks in clsCtlCbo you have 
code that "swaps" the unfiltered and filtered queries as required.

In the form's OnOpen where you load the clsFrm, you then "program" the form.  For those combos that 
do not need this functionality you do not program a filtered query into the combo.  For example a 
state combo will almost never be filtered (although even that is possible in certain circumstances) 
so you would just leave the state combo unfiltered all the time (for the purposes of this example). 
  OTOH, the contract combo needs to be filtered to only allow the user to select an active contract 
when creating a new record.  So this combo needs to be "programmed" when clsFrm loads with the name 
of the filtered query, or the SQL statement that loads the filtered data.

I mentioned in one of the lectures that the OnOpen of the form would become form programming central 
as we added functionality to the various classes.  This is just such an example.

There have been discussions on how to accomplish this in past threads, and the GotFocus / LostFocus 
shuffle seems to be the accepted method.

John W. Colby
www.ColbyConsulting.com


Mike Mattys wrote:
> OK, what I was thinking was that you'd have a global class
> that is instantiated while the database is open and you'd just
> call a method in the class with the record number of the string
> that would be the new recordsource of the combo.
> 
> -
> Michael R Mattys
> MapPoint and Database Dev
> www.mattysconsulting.com




More information about the AccessD mailing list