Stuart McLachlan
stuart at lexacorp.com.pg
Sun Feb 22 06:39:54 CST 2009
Here's my simple procedural take on the problem.
I started thinking about ways to avoid stepping through the whole controls collection for the
form and to optimise looping through the ones we are interested in.
This method opens a form containing over 200 labels and buttons with no discernable delay.
All that is required is that you:
a. Maintain a standard naming convention for Labels and Buttons:
Label1, Label2 etc and Button1001,Button1002 etc within the form
b. Define a FormID constant in each form's module,
c. Define constants in each form's module which record the number of labels and buttons
d. Store your translation strings with two fields, FormNumber and ControlNumber
FormNumber - Long
ControlNumber - Long
Language1 - String
Language 2 - String
Language 3 - String
etc
1. When the user changes language, load the new one into a Translation collection.
In a Module:
Global gcolTranslation As New Collection
Function GetLanguage(Language as long)
Dim rs as DAO Recordset
If gcolTranslation.Count > 0 Then
For i = 1 To gcolTranslation.Count
gcolTranslation.Remove 1
Next
End If
Set rs = currentdb.openrecordset("uSysTranslationTable")
While not rs.eof
gcolTranslation.Add rs(Language + 2), _
Format(rs(0),"00") & rs(1)
rs.movenext
wend
rs.close
set rs = nothing
End Function
2. In each Form create 3 constants:
Const FormID As String = "01"
Const NoOfLabels As Long = 200
Const NoOfButtons as Long = 5
3. Use the following on_open event for each form.
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
Dim x As Long
Dim sX As String
For x = 1 To NoOfLabels
Me("Label" & x).Caption = gcolTranslation(FormID & x)
Next
For x = 1001 To 1000 + NoOfButtons
Me("Button" & x).Caption = gcolTranslation(FormID & (x)
Next
End Sub
--
Stuart