[AccessD] Find First in an Array?

jwcolby jwcolby at colbyconsulting.com
Thu Feb 19 12:52:32 CST 2009


Gustav,

I don't care what you do with the recordset you still have to move through it to get to the correct 
control record, then you have to reference the right field to get the string etc.  To use a 
collection all you do is (psuedocode of course):


dim col as collection

	open recordset
	while not rst.eof
		col.add rst!TranslationFld, rst!CtlNameFld
		.movenext
	wend
	close recordset

Dimension a collection.  Open the recordset.  Iterate through the recordset dropping the translation 
field into the collection, keyed on control name.  This only has to be done one time and you are 
through with the recordset.

To get it back out all you need to do is:

dim ctl as control
	
	for each ctl in form.controls
		on error resume next
		ctl.Caption = col(Ctl.Name)
	next

Dimension a control.  Iterate through the form's control collection.  Use each control's name to 
index into the collection.  If a value exists it is moved into the caption otherwise it moves to the 
next control.

It doesn't get any easier and it WILL be faster, almost assuredly by a LOT.  Probably a hundred or 
more times faster.  Pulling the data out of the collection and stuffing it into controls will be 
BLAZING fast.  Almost certainly under a millisecond.

John W. Colby
www.ColbyConsulting.com


Gustav Brock wrote:
> Hi John
> 
> But why not just load the recordset as static when you initialize the class? Zero additional code, no fuzzing with collections etc.
> 
> /gustav
> 
>>>> jwcolby at colbyconsulting.com 19-02-2009 18:47 >>>
> ICK!
> 
> This application is PERFECT for caching.  The data does not change from the time the database opens 
> to the time it closes.  The data is loaded once into collections and then the form is loaded from 
> its specific collection (class instance).  If you are going to run through the entire recordset 
> every time the form opens... why not simply load the data into a collection the first time and let 
> the poor disk take a nap?
> 
> This is not rocket science.  In fact if I hadn't had some calls from clients interrupt me it would 
> be done already.
> 
> John W. Colby
> www.ColbyConsulting.com 




More information about the AccessD mailing list