Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To run a code which his source text is from a table

Status
Not open for further replies.

meirfridman

Technical User
Feb 13, 2011
12
BE

Hello all,

Is it possible to run a code which his source text is from a table?
I mean, instead of writing:
Code:
me.cmdClose.Caption = "Close"
To write:
Code:
ButtenLanguage = DLookup("fldAdress", "tblLanguagesInForms")
When the value in "fldAdress" is 'me.cmdClose.Caption = "Close" '

Because when I writes:
Code:
ButtenLanguage = DLookup("fldAdress", "tblLanguagesInForms")
ButtenLanguage
He returns Me an error("Expected Sub, Function, or Property"....)

Thanks in advance
 

Hi MakeItSo,

Thanks a mill. for that. However it does not seem to work. (after this short paragraph of explanation for those less knowledgeable than you) I have pasted the code I entered that still does not seem to do it, giving me an “object required” error message.

I am trying to build an interface that will work in a few languages. What I would like is to have a single interface that the user can choose to see and use in the language of choice.
The user needs to get his buttons and labels in his own language and the text input has to be stored divided too (to allow effective cross language searching).

In an attempt to achieve this I created a table containing the different language options.

e.g.
fldFormId
fldAdress (values: cmdClose, txtArticleName)
fldProperty (values: Caption, ControlSource)
fldValueEN (values: “Close”, “fldArticleNameEN”)
fldValueFR (values: “Ferme” “fldArticleNameFR”)

Essentially all data should be combined into one single record regardless of what language it was entered in.

The code I wrote looks like this:

Code:
Dim FormId As Long
Dim Language, LanguageValue As String
Dim F_Adress, F_Property, F_Value, F_Chaining As String
Dim rstFormLanguage As Recordset

FormId = 1
Language = "EN"
LanguageValue = "fldValue" & Language

Set rstFormLanguage = CurrentDb.OpenRecordset("SELECT fldFormId, fldAdress, fldProperty, " & LanguageValue & " AS R_Value " _
                                  & "FROM tblLanguagesInForms WHERE (((tblLanguagesInForms.fldFormId) =" & FormId & "))")

rstFormLanguage.MoveFirst

Do While Not rstFormLanguage.EOF

F_Adress = rstFormLanguage("fldAdress")
F_Property = rstFormLanguage("fldProperty")
F_Value = Replace(rstFormLanguage("R_Value"), "'", "''")

F_Chaining = "me." & F_Adress & "." & F_Property & " = " & F_Value

[COLOR=blue]HERE I'M STUCK !!!!![/color]

rstFormLanguage.MoveNext

Loop
Part of the objective is to allow the user to adapt the interface as well as to add more languages in the future without touching the code.

Thanks in advance, and a very fine day to you (all),

meirfri

 
Urrmmmmm... I think you are over complicating things here and I don't think you're going to need a Script control after all.

1.) Try this:
Code:
Do While Not rstFormLanguage.EOF

F_Adress = rstFormLanguage("fldAdress")
F_Property = rstFormLanguage("fldProperty")
F_Value = Replace(rstFormLanguage("R_Value"), "'", "''")

[s][red]F_Chaining = "me." & F_Adress & "." & F_Property & " = " & F_Value[/red][/s]

Replace the strikeout line with:
Code:
Me.Controls(F_Adress).Properties(F_Property) = F_Value

Hope this helps!

Cheers,
MakeItSo

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 

Also, just FYI:
Code:
Dim FormId As Long
Dim [red]Language[/red], LanguageValue As String
Dim [red]F_Adress, F_Property, F_Value[/red], F_Chaining As String
Dim rstFormLanguage As Recordset
All [red]RED[/red] variables are Variants.

Consider:
Code:
Dim FormId As Long
Dim Language [blue]As String[/blue], LanguageValue As String
Dim F_Adress [blue]As String[/blue], F_Property [blue]As String[/blue], F_Value [blue]As String[/blue], F_Chaining As String
Dim rstFormLanguage As Recordset
Not a big deal, but it is good to know....

Have fun.

---- Andy
 


Thanks you two.

MakeItSo; I did what you said and indeed it works, so thanks for that. Progress. However, it only works for the controls in the main form not in the subforms. Is there any way round that that you can think of?

The source code for the controls looks like this, if that is any help:

fldFormId (value: 1)
fldAdress (value: subfrmTypes!cmdNewType)
fldProperty (value: Caption)
fldValueEN (value: "New Type")
fldValueFR (value: "Nouveau Type")

Looking forward in desperation to any help I can get at the moment.

Meirfri

 
Ah, I see!

In that case try replacing "Me.Controls(..." with
"Forms(fldFormId).Controls(..."

That should already do the trick.

:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top