
Using Variable Names in SQL queries.....
Hi,
Does anyone know how to use variable names in SQL queries? Here's my
problem:
I have a searchbox to find a record in a Dynaset. I have a combo box that
lists all the field in my database and a text box that the user types in the
search pattern to look for. Now, I can use a variable to represent the
search string, but I can't use a variable to represent the field name that I
want to search on.
ie.
Select * From myTable WHERE COMPANY Like 'A*'
would return all the companies that start with A from myTable.
But, I want to replace myTable, COMPANY, and 'A*' all with variables. That
way the user can choose what field to search on.
I got the following syntax from the programmers reference:
'" & variablename & "'
making the statement:
Select * From myTable WHERE COMPANY Like '" & variable1 & "'
This line works, but when I try and change COMPANY to a variable, it fails.
Any ideas? I can't imagine it being to different, but I am probably missing
something obvious......... Any help is greatly appreciated.
Thanks.
Walter