IIf Controlsource GOTCHA!

S

Seb Thirlway

Just posting this so that some poor soul can search GoogleGroups with
"Iif" and "Controlsource" and find the answer, rather than tearing his
hair out like I did.

Why is my textbox, whose Controlsource is:

Iif([DataField1]="something","some text" & [DataField2],"something
else")

always showing the WRONG value? It seemed to be picking up the same
value of DataField2 for all the 3 rows in the detail section.
Huh? checked the query, checked the report, tried it, tried again,
racked my brain, closed down Access and restarted, went out for a
cigarette, racked my brain some more and so on...

The reason is: Access' annoying habit of naming the textbox (or
whatever) with the SAME NAME as the underlying data field in the
Recordsource, when you drag a field from the Field List onto a report
or form.
So my text box was getting its value from a textbox in the group
header, which was, of course, called DataField1. No wonder all the
detail rows looked the same.

If you have a control on a report or form, and a field in the
recordsource with the same name, Access will assume you're referring
to the control. This only seems to affect functions in Controlsources
(if I'd set the Controlsource to just DataField1, I'd have got the
right result).

If this helped you out, buy me a drink (you'll have to drink it
yourself)



Seb
 
Top