Discussion:
macro Substitution
(too old to reply)
Mervyn Bick
2008-09-24 16:01:57 UTC
Permalink
Im using macro substitution for the first time and Im having a little
problem
....
for fieldcount = 1 to rControls.fields.size
cmd = "form." + trim(rControls.fields[fieldcount].fieldname) +
".text = " + trim(rControls.fields[fieldcount].value)
&cmd
endfor
I am prompted with 'Expression expected' on the &cmd command.
Any ideas??
The first thing I do when a macro doesn't work as expected is to
temporarily change the & to ? which will cause the contents of the
variable to print. Nine time out of ten the string is not what I had
intended it to be and I can then set about correcting it.

Mervyn.
Marc Hamelin
2008-09-24 17:20:15 UTC
Permalink
cmd = "form." + trim(rControls.fields[fieldcount].fieldname) +
".text = " + trim(rControls.fields[fieldcount].value)
Since you are adding a string to the text property, you must enclose the
actual value within character delimiters like this: '<your_value>' or
"<your_value>" or [<your_value>]. Try this instead:

cmd = "form." + trim(rControls.fields[fieldcount].fieldname) + ".text = [" +
trim(rControls.fields[fieldcount].value) + "]"

If your fields are numerical values instead of character values, then you
should not use the Trim() function:

cmd = "form." + trim(rControls.fields[fieldcount].fieldname) + ".text = " +
rControls.fields[fieldcount].value

Hope this helps.

Marc Hamelin
John Noble
2008-09-24 17:41:22 UTC
Permalink
Thanks Guys,

The following code seems to work OK.

cmd = "form." + trim(rControls.fields[fieldcount].fieldname) + ".text =
trim(rControls.fields[fieldcount].value)"
&cmd

John

Loading...