Using a variable derived from a drop-down list as the column name in a select statement ... Access DB

Posted by user1459698 on Stack Overflow See other posts from Stack Overflow or by user1459698
Published on 2012-06-15T20:37:36Z Indexed on 2012/06/15 21:16 UTC
Read the original article Hit count: 163

Filed under:
|
|
|
|

I'm working with the world's worst DB that was already here so don't blame me for that.

So, here's what I have so far ...

module = txtModule.value
presstype = txtPressType.value

SQL_query = "SELECT * FROM tbl_spareparts WHERE '"& module &"' <> '""' AND '"& module &"' = '"& presstype &"' AND Manufacturer = '"& txtsrch.value &"' ORDER BY SAP_Part_No"
Set rsData = conn.Execute(SQL_query)

This brings up the following SQL statement:

SELECT * FROM tbl_spareparts WHERE 'Banyan_Module' <> '"' AND 'Banyan_Module' = 'PB' AND Manufacturer = 'Tester' ORDER BY SAP_Part_No

Is there any way I can use the module variable as a column name - obviously the ''s around the column name are causing an error. This is really bothering me.

BTW, I'm writing this in VBScript inside a .HTA application page as it has to run locally on tech PCs.

Thanks.

R.

© Stack Overflow or respective owner

Related posts about sql

Related posts about database