Language table for labels/subform problem

M

Michel

I am developing a front-end that has to be bilingual. I set up a
tblLanguage with the following field

FormName
ControlName
ControlType
DateUpdated
English
French

The following code works fine for all forms with no subform. The
problem I would like to know how to resolve regards subform. I cannot
make this work for the labels on the subform. I added ***** where I get
a VB error.

Any suggestion on how to resolve this would be very appreciated.

Thanks

Michel


Private Sub langSetControls(recLang As Recordset, _
strLang As String, strFormName As String)

Dim FrmF As Form
Dim ctlc As Control
Dim strControlName As String
Dim intControlType As Integer


**********Set FrmF = Forms(strFormName)*********************

With recLang
.Seek "=", strFormName, strFormName

'add or update the form in the language table

If .NoMatch Or IsNull(.Fields(strLang)) Then
FrmF.Caption = ""
Else
FrmF.Caption = .Fields(strLang)
End If

'now loop through the controls
For Each ctlc In FrmF.Controls

'we are only interested in the controls
'with a caption property

intControlType = ctlc.ControlType
If ControlHasCaption(intControlType) = True Then
'find the control in the language table
strControlName = ctlc.Name
.Seek "=", strFormName, strControlName

'add or update the control in the language table
If .NoMatch Or IsNull(.Fields(strLang)) Then
ctlc.Caption = ""
Else
ctlc.Caption = .Fields(strLang)
End If
End If
Next
End With

End Sub


Private Function ControlHasCaption(intCtlType As Integer) As Boolean

Select Case intCtlType
Case acCommandButton, acLabel, acToggleButton
ControlHasCaption = True
Case Else
ControlHasCaption = False
End Select

End Function

Private Function ControlTypeName(intCtlType As Integer) As String

Select Case intCtlType
Case acLabel
ControlTypeName = "Label"
Case acCommandButton
ControlTypeName = "Command button"
Case acToggleButton
ControlTypeName = "Toggle button"
End Select

End Function

Public Sub OpenFormLanguage(bolExtract As Boolean, strLang As String,
strFormName As String)

Dim db As DAO.Database
Dim recLang As DAO.Recordset

'Open the database and language recordset

Set db = CurrentDb()
Set recLang = db.OpenRecordset(wcsLANGUAGETABLE)
recLang.Index = "PrimaryKey"

If bolExtract Then
LangExtractControls recLang, strLang, strFormName
Else
langSetControls recLang, strLang, strFormName
End If

'close up
recLang.Close

End Sub
 
G

Graham Mandeno

Hi Michel

This is because subforms are not top-level members of the Forms collection.
To get to a subform you need to say:
Set FrmF = Forms(MainFormName)(SubformControlName).Form

Are you calling your procedure from the forms' Open event procedures?

If so, then pass the form object (Me) instead of the name:
Public Sub (bolExtract As Boolean, _
strLang As String, frm as Form)

Call it like this:
Call OpenFormLanguage (True, "fr", Me)

You can get the form name (for your table lookup) from frm.Name

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 

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