Use variables in sql statement
I've built an sql string to get records from a database and store to excel.
sSql = "SELECT * FROM myTableName"
I want to replace myTableName with a variable (TableVar) to reference the
tablename typed in Cell A1.
I assigned the variable TableVar by doing the following:
TableVar = ActiveWorkbook.Worksheets("sheet1").Range("B1").Va lue
When I replace myTableName with TableVar, I get an error message that there
is no such table as TableVar.
What is the correct way to replace a table name with a variable?
|