T
TerryL
Some languages allow you to force the interpreter to evaluate the contents of
a variable in a command before the command is executed. Is there a way to
do this in VBA. Here is an example.
The objective is to develop a common routine to apply a set of
transformation rules to the contents of a field in a table. The name of the
table and the name of the field is supplied to the routine in string
variables. The table name is not a problem since the OpenRecordSet command
uses a string for the table name. It is the field name I am having a problem
with. In the update section the logic looks like:
recordset.Edit
recordset!FieldnameVariable = strfieldvalue
recordset.Update
Where both FieldnameVariable and strfieldvalue are string variables defined
in DIM statements. The value of FieldnameVariable changes with the table
name supplied. As the code is presented above, you get an error because
"FieldnameVariable" is not a column name defined in any table. If the
contents of FieldnameVariable is "ActualFieldName", how can I force VBA to
substitute the variable contents in the command so it looks like:
recordset!ActualFieldName = strfieldvalue
when it gets excuted.
a variable in a command before the command is executed. Is there a way to
do this in VBA. Here is an example.
The objective is to develop a common routine to apply a set of
transformation rules to the contents of a field in a table. The name of the
table and the name of the field is supplied to the routine in string
variables. The table name is not a problem since the OpenRecordSet command
uses a string for the table name. It is the field name I am having a problem
with. In the update section the logic looks like:
recordset.Edit
recordset!FieldnameVariable = strfieldvalue
recordset.Update
Where both FieldnameVariable and strfieldvalue are string variables defined
in DIM statements. The value of FieldnameVariable changes with the table
name supplied. As the code is presented above, you get an error because
"FieldnameVariable" is not a column name defined in any table. If the
contents of FieldnameVariable is "ActualFieldName", how can I force VBA to
substitute the variable contents in the command so it looks like:
recordset!ActualFieldName = strfieldvalue
when it gets excuted.