Using a variable derived from a drop-down list as the column name in a select statement ... Access DB
- by user1459698
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.