Control Source SQL syntax

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Everyone,

On the Control Source of an element on a subform, I've typed "Select
Reason_Description from Reason_Codes where Reason_Code=[Me]![Reason_Code]",
where Reason_Code is an element on the subform line.

I'm sure my syntax is incorrect (or at least Access doesn't like it, lol).

Some help, please
Pat.
 
You cannot place a SQL statement into the Control Source of a control.

Instead use DLookup(). Something like this:
=DLookup("Reason_Description", "Reason_Codes",
"Reason_Code = " & Nz([Reason_Code],0))

For details, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
Thanks Allen - that did the trick - best of all, I leasrned something new
today.
Cheers
Pat.

Allen Browne said:
You cannot place a SQL statement into the Control Source of a control.

Instead use DLookup(). Something like this:
=DLookup("Reason_Description", "Reason_Codes",
"Reason_Code = " & Nz([Reason_Code],0))

For details, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pat Backowski said:
On the Control Source of an element on a subform, I've typed "Select
Reason_Description from Reason_Codes where
Reason_Code=[Me]![Reason_Code]",
where Reason_Code is an element on the subform line.

I'm sure my syntax is incorrect (or at least Access doesn't like it, lol).
 
Back
Top