Hi
Controlsource is a string property - whatever you set as the
Controlsource is evaluated at runtime (every time you move to a new
record, assuming the text box is in the Detail section - and every time
you do a Form.Reqery) to give the text box a Value.
What I _think_ you're trying to do here is set the text box up so that
whenever the text box is recalculated, from this moment on (or until
you change the Controlsource again in code, if you do), it'll get its
value from the DLookup function.
If this is what you're trying to do, you need to set the Controlsource
to the STRING
"DLookup(""[AADT]"",""[VcValueQry2]"")"
(NB double " ("") must be used within quotes to stand for ")
If, on the other hand, you just want to set the Text box's value to the
result of the DLookup, just now, just once, without it being ever
recalculated, then you should set the
Value property:
Me!txtAADT1.Value = DLookup("[AADT]", "[VcValueQry2]").
The code as you've posted it:
Me!txtAADT1.ControlSource = DLookup("[AADT]", "[VcValueQry2]")
will evaluate the DLookup function at the time this line executes, find
that the result is e.g. "Some words" or 6, and then set the text box's
Controlsource to "Some words" or "6". Then Access will evaluate the
Controlsource to work out the text box's Value. I don't think this
(two evaluations) is what you're meaning to do - unless the DLookup
actually does return a function or expression such as "Now()",
"[NameOfAFieldInTheRecordsource]" etc.
When the COntrolsource is evaluated:
a) If the ControlSource is numeric, (e.g. "6") it'll just set the Text
box to that value.
b) If the Controlsource is nonnumeric, it must be a function, or an
expression referring to a control on an open form or to a field in the
form's Recordsource. I suspect that whatever your DLookup is returning
is nonnumeric, which is why you're getting #ERror# in the text box.
cheers
Seb