comments inline.
tatamata said:
Hello.
I want to internationalize my. mde application forms and reports.
Is it possible to iterate through all labels in all forms an reports, get
their Caption property values, put them in some local JET table and then use
it for other language translations?
yes, it should be possible.
I thought to add translations as columns to that local table, so that during
start-up, my application cheks which language is currently selected and then
dynamically set Caption property value for every label in every form and
report...
by "columns", you mean *fields* in the table. creating a field for each
language, as
tblCaptions
ObjectType
ObjectName
LabelName
English
Spanish
German
<etc, etc, etc>
is NOT normalized table structure. instead, suggest the following two-tables
structure, as
tblLabels
LabelID (autonumber, primary key)
ObjectType
ObjectName
LabelName
tblLabelCaptions
LabelID (foreign key from tblLabels)
Language
(use these two fields as a combination primary key, or add an autonumber
field to serve as the primary key, if you like.)
LabelText
What do you think about this approach? Is there any similar approach already
implemented? Some examples? Some advices?
How to iterate through all reports and forms and get all Caption property
value for all labels?
to populate the table with form and report label names, try the following
code, as
Public Sub getForms()
Dim dbs As Object, obj As Object, ctl As Control, frm As Form
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
DoCmd.OpenForm obj.Name
Set frm = Forms(obj.Name)
For Each ctl In frm.Controls
If TypeOf ctl Is Label Then
CurrentDb.Execute "INSERT INTO tblLabels " _
& "( ObjectType, ObjectName, LabelName ) " _
& "SELECT 'Form', '" & frm.Name & "', '" _
& ctl.Name & "'", dbFailOnError
End If
Next ctl
DoCmd.Close acForm, obj.Name, acSaveNo
Next obj
End Sub
Public Sub GetReports()
Dim dbs As Object, obj As Object, ctl As Control, rpt As Report
Set dbs = Application.CurrentProject
For Each obj In dbs.AllReports
DoCmd.OpenReport obj.Name, acViewPreview
Set rpt = Reports(obj.Name)
For Each ctl In rpt.Controls
If TypeOf ctl Is Label Then
CurrentDb.Execute "INSERT INTO tblLabels " _
& "( ObjectType, ObjectName, LabelName ) " _
& "SELECT 'Report', '" & rpt.Name & "', '" _
& ctl.Name & "'", dbFailOnError
End If
Next ctl
DoCmd.Close acReport, obj.Name, acSaveNo
Next obj
End Sub
the two procedures are nearly identical, except for the form vs report
references. i was too lazy to come up with a more elegant way of doing it,
in one procedure.
to iterate through the controls in a single object and find the labels, try
the code below. you can use it for setting label captions on form Load
events, and report Open (probably) events.
Public Function SetCaption()
Dim ctl As Control
With CodeContextObject
For Each ctl In .Controls
If TypeOf ctl Is Label Then
<put here the code to change the label's Caption property>
End If
Next ctl
End With
End Function
paste the function into a public module, so it can be called from anywhere
in the database.
hth