Dynamically change label of a field (1 Viewer)

calvinle

Registered User.
Local time
Today, 00:16
Joined
Sep 26, 2014
Messages
332
Hi,

I have form with a subform. On my main form, there is a field "language", so I would like to dynamically manipulate all label associated to the field in the subform to change depending on the language chosen in the main form.

Here is my code for a single field, but I want to be able to loop through all field within the subform:
Code:
  If Nz(Me.txtLang) = "English" Then
    Me.subform.Form!leg_ent_nm_lbl.Caption = Nz(DLookup("txt_label", "label_fld_t", "txt_fld = """ & Me.subform.Form!leg_ent_nm.Name & """"))
  Else
    Me.subform.Form!leg_ent_nm_lbl.Caption = Nz(DLookup("txt_label_fr", "label_fld_t", "txt_fld = """ & Me.subform.Form!leg_ent_nm.Name & """"))
  End If
Any help is appreciated.

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:16
Joined
Oct 29, 2018
Messages
21,358
Hi. One way is to "tag" each label to change and loop through the controls. For example:
Code:
Dim ctl As Access.Control
For Each ctl In Me.SubformControlName.Form
    If ctl.Tag = "ChangeLabel"
        ctl.Caption = "something"
    End If
Next
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:16
Joined
Feb 28, 2001
Messages
27,001
There are dozens of ways to handle this, but in general you have to be able to identify the labels you want to change. How you do this is on you, but theDBguy's suggestion is one common way. Another is that if you have a table of label names and the text you want to use in each, you can look through the recordset and use two fields from the table - the control name and the new caption, i.e.

Code:
Me.Controls(rs.control-name).Caption = rs.control-text

This might be a complex process if you have a lot of these to change on a lot of forms, because you might need a hierarchical table structure and an OUTER JOIN query to drive it all. The question is going to be just how extensive will this language change be? Are we talking 10 labels on a single form? Build a SELECT CASE in the form's OnLoad event and just set the captions according to the language. Are we talking 10 forms and at least 5 to 10 controls per form? Now you need something with more complexity.
 

Users who are viewing this thread

Top Bottom