Hello,
Is it possible to build and execute dynamic code statements in VB?
For example, consider the statement
Me!txt_Name1.Value = "Name1"
The text control could have been a different one from "txt_Name1" depending on certain criteria. The statement could as well have been
Me!txt_Name2.Value = "Name2"
Is it possible to use a string to hold the entire code statement like
Dim strCode as string
Dim strTxtFieldName as String
If <condition 1> Then
strTxtFieldName = "txt_Name1"
Else
strTxtFieldName = "txt_Name2"
End If
strCode = "Me!" & strTxtFieldName & ".Value = 'Name1'"
and execute this statement?
The reason for asking is that the form I am working with has about 100 text fields and the criteria is quite complicated that if I have to hard code the text field names with IF..THEN..ELSE or SELECT..CASE statements, the code can become a real mess.
Thanks