View Full Version : How to call Form values in a SQL Query


K0k1man
05-14-2007, 07:47 AM
Hi,

I need to build a query where upon form input a different table gets queried.

SELECT *
FROM ((Forms!DCL!PortDropDown))
WHERE ((Forms!DCL!DestinationList=(Reg_Dest.Destination) ));

The "FROM" is my problem. The "WHERE" is working. I am getting a "SYNTAX ERROR IN JOIN OPERATION" error message. Please help.

Thank you:confused:

rainman89
05-14-2007, 07:56 AM
you select from a table not a form. are the values in the drop down listed in a table?

K0k1man
05-14-2007, 08:09 AM
Hi and thanks for the help.

The form drop down (PortDropDown) value is the name of the table to be queried

rainman89
05-14-2007, 09:16 AM
I tried making a sample db for you, but i couldnt get it to work correctly. im sure someone else will be of more help than i. good luck

pbaldy
05-14-2007, 09:23 AM
You'll have to build the SQL in VBA, as you can't use a form value for the FROM clause. This type of problem often hints at a design problem. I would question why you have tables for each port, rather than 1 table with a field to indicate the port.

K0k1man
05-14-2007, 10:19 AM
I see.... I will look into that advice and will also see about SQL in VBA.

thanks

KeithG
05-14-2007, 10:29 AM
Search the forum for Dynamic SQL. I have posted some examples in the past.