Hi Mike,
Your suggestion led me on the right direction. This morning I thought the whole thing will take 2 or 3 of my already few days to deadline but at the end of today I had it done.
I'm posting the whole result, just in case someone else needs this in the future. Or if someone wants to suggest an improvement it'll be more than welcome.
Cheers,
Sergio
-------------------------------------
Solution to have multiple languages on a single Access Application
1. Create a table with your original description and its foreign description
SAMPLE
'I use rowid (autonumber) as a standard in my tables
english chinese rowid
Bin Maintenance ¿âûµ÷Ãû 39
Bin to bin transfers ¿âûµ÷Ãû 27
2. Create a translation function:
Function getLanguage(variable As String) As String
'I leave the very first form open but hidden,
' with a text control having the selected language
If Forms!LanguageSelection.language = "english" Then
getLanguage = variable 'No changes
Else
'Some buttons don't have description, so nothing to translate
If Nz(variable, "") <> "" Then
getLanguage = Nz(DLookup("[chinese]", "shanman_syslangmatrix", "[english] = " & qo(variable)), "@" & variable)
'The @ will indicate me if a description doesn't have a matching translation yet
Else
getLanguage = variable 'No changes if blank captions (without this it was changing them to @)
End If
End If
End Function
3. Create a procedure to translate all controls in the form
Public Sub translateForm(frm As Form)
On Error GoTo Exit_translateForm 'Until I find a way to know the number of controls
'the error is the loop exit
Dim i As Integer
Dim j As Integer
Dim x As String
For i = 0 To 1000 'I don't think I'll have more than 1,000 controls in a form ...
j = frm.Controls(i).ControlType
If j = 100 Or j = 104 Then 'I only want to translate Labels & Buttons
frm.Controls(i).Caption = getLanguage(frm.Controls(i).Caption)
End If
Next i
Exit_translateForm:
End Sub
4. Guess what? It works on reports too
Public Sub translateReport(rep As Report)
On Error GoTo Exit_translateReport 'Until I find a way to know the number of controls
'the error is the loop exit
Dim i As Integer
Dim j As Integer
Dim x As String
For i = 0 To 1000 'I don't think I'll have more than 1,000 controls in a report ...
j = rep.Controls(i).ControlType
If j = 100 Or j = 104 Then 'I only want to translate Labels
rep.Controls(i).Caption = getLanguage(rep.Controls(i).Caption)
End If
Next i
Exit_translateReport:
End Sub
5. Put the corresponding routine as part of your ON LOAD event of form or your ON OPEN event of report
Private Sub Form_Load()
translateForm Me
End Sub
Private Sub Report_Open(Cancel As Integer)
translateReport Me
End Sub
|