[AccessD] Find First in an Array?

Stuart McLachlan stuart at lexacorp.com.pg
Wed Feb 25 04:55:37 CST 2009


In the absence of the sample DB, function Startup() below may need a 
minor modification.

Here's the *total* code required to do the translations with a Collection, 
which is indexed on Form,Control and Language (other than to add 
"SetCaptions Me.Name" in each forms on_open).


Option Compare Database
Option Explicit
Global gcolTranslation As New Collection
Global glngLanguage As Long

Function StartUp()
'Code which is run when the application starts
Dim rs As DAO.Recordset
Dim x As Long
'Fill Collection
Set rs = CurrentDb.OpenRecordset("tblLanguages")
While Not rs.EOF
    For x = 2 To rs.Fields.Count - 1
    gcolTranslation.Add rs(x), _
         rs!FormName & Chr$(0) _
         & rs!ControlName & Chr$(0) _
         & Format(x - 2, "00")
    Next
    rs.MoveNext
Wend
'Get current default language
glngLanguage = DLookup("Language", "uSysDefaults")

End Function

Function SetCaptions(frm As Form)
Dim ctl As Control
'skip labels which don't have a translation
On Error Resume Next
For Each ctl In frm
  For Each ctl In frm.Controls
    If ctl.ControlType = acLabel Then
      ctl.Caption = gcolTranslation(frmName _
           & Chr$(0) & ctl.Name _
           & Chr$(0) & Format(glngLanguage, "00"))
    End If
Next ctl
End Function

Function SetLanguage(Language As Long)
Dim frm As Form
CurrentDb.Execute "Update uSysDefault Set Language = " & Language
'update all open forms
For Each frm In Application.Forms
   SetCaptions frm
Next
End Function




More information about the AccessD mailing list