iteration through Caption property of all labels

T

tatamata

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?
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...
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?
Thank you in advance,

Zlatko
 
T

tina

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
 
G

Guest

Hi Zlatko,

To add to Tina's answer, you might want to check out the August, 2006 issue
of Access Advisor magazine:

Localize Microsoft Access Applications On-The-Fly
Accommodate multiple languages using a table-driven, front-end solution.
http://zones.advisor.com/doc/18129


I believe Advisor sells single issues of this publication.

Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top