[AccessD] Find First in an Array?

Drew Wutka DWUTKA at Marlow.com
Wed Feb 18 19:08:55 CST 2009


Here is a VERY down and dirty example of how to use a collection for
this Rocky:

Dim CommandTranslations as Collection
Dim rs as Recordset
Dim strSQL as string
Set CommandTranslations=New Collection
Set rs=new ADODB.Recordset
strSQL="SELECT CommandName, Language, Translation FROM
tblCommandTranslations"
rs.open strsql,currentproject.connection,adopenkeyset,adlockreadonly
if rs.eof=false then rs.movefirst
do until rs.eof=true
	CommandTranslations.Add rs.fields(2).value,rs.fields(0).value &
_
	":" & rs.fields(1).value
	Rs.movenext
Loop
Rs.close
Set rs=nothing

(I hope the syntax for all that is right, I wrote it out just in this
email...)

Once this is done, you now have CommandTranslations as a collection of
your commands in their proper language.  I am assuming you have a table
with a 'commandname' (such as a control name), 'Language', and
'Translation'.

So to use this collection, you would simply do this:

Dim strLanguage As String
Dim ctrl
strLanguage="English" 'or whatever you use to determine the language
for each ctrl in me.Controls
	ctrl.Caption=CommandTranslations(ctrl.Name & ":" & strLanguage)
next

Now, to give a little explanation as to what we did here....

A collection has two ways of indexing.  An Integer position (and
collections are 1 based (ie, SomeCollection(1) is the first object,
instead of 0)) and a string 'custom' key.  You also don't even need a
key to 'run through' a collection (you can use the for each x in
xCollection method).  The custom key has to be unique.  But it's GREAT
for finding information quickly!

So we created a custom key by putting the command name and the language
together (joined with a semicolong).  Their should only be one of each
command name, and by putting the language with it, they should all be
unique.

And Walla, an instance retrieval of any command with it's language.

Now, personally, I would recommend that you make a Global Class to
handle this.  Put in some errorhandling in case it runs into a control
that doesn't have a translation...etc.  But the above is the shotgun
method!

Drew

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin
at Beach Access Software
Sent: Wednesday, February 18, 2009 6:11 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Find First in an Array?

Collection, eh?  Hmm....back to the ADH! 


Rocky Smolin
Beach Access Software
858-259-4334
www.e-z-mrp.com
www.bchacc.com
 
The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.





More information about the AccessD mailing list