ControlSource Not Working

D

DS

I have this SQL statement to set the value of a TextBox, but all I get
is #NAME? am I missing something...

Me.TxtStart.ControlSource = "SELECT MenuDetails.StartTime " & _
"FROM MenuDetails " & _
"WHERE (((MenuDetails.TerminalID)=[Forms]![Form9]![TerminalID]) " & _
"AND ((MenuDetails.MenuID)=[Forms]![Form9]![TxtMenuID " & _
"AND ((MenuDetails.StartDay)=2));"

Thanks
DS
 
R

Rick Brandt

DS said:
I have this SQL statement to set the value of a TextBox, but all I get
is #NAME? am I missing something...

Me.TxtStart.ControlSource = "SELECT MenuDetails.StartTime " & _
"FROM MenuDetails " & _
"WHERE (((MenuDetails.TerminalID)=[Forms]![Form9]![TerminalID]) " & _
"AND ((MenuDetails.MenuID)=[Forms]![Form9]![TxtMenuID " & _
"AND ((MenuDetails.StartDay)=2));"

What you are missing is that a Control's ControlSource cannot be a SQL
Statement. It can be a field name from the form's RecordSource or an expression
that evaluates to a single value. A SQL statement (even one that returns a
single field in a single row) cannot be used.

You could have that SQL in a saved query and then use a DLookup() expression to
retrieve it.
 
D

DS

DS said:
I have this SQL statement to set the value of a TextBox, but all I get
is #NAME? am I missing something...

Me.TxtStart.ControlSource = "SELECT MenuDetails.StartTime " & _
"FROM MenuDetails " & _
"WHERE (((MenuDetails.TerminalID)=[Forms]![Form9]![TerminalID]) " & _
"AND ((MenuDetails.MenuID)=[Forms]![Form9]![TxtMenuID " & _
"AND ((MenuDetails.StartDay)=2));"

Thanks
DS
Never Mind, Murphys Law, I remembered that its DLookUp not SQL!
Thanks
DS
 
D

DS

Rick said:
DS said:
I have this SQL statement to set the value of a TextBox, but all I get
is #NAME? am I missing something...

Me.TxtStart.ControlSource = "SELECT MenuDetails.StartTime " & _
"FROM MenuDetails " & _
"WHERE (((MenuDetails.TerminalID)=[Forms]![Form9]![TerminalID]) " & _
"AND ((MenuDetails.MenuID)=[Forms]![Form9]![TxtMenuID " & _
"AND ((MenuDetails.StartDay)=2));"


What you are missing is that a Control's ControlSource cannot be a SQL
Statement. It can be a field name from the form's RecordSource or an expression
that evaluates to a single value. A SQL statement (even one that returns a
single field in a single row) cannot be used.

You could have that SQL in a saved query and then use a DLookup() expression to
retrieve it.
Thanks
Rick, I remember Now!
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top