I have a SQL query (through an ODBC connection) that populates an Excel spreadsheet. The thing is that I want add a criteria "WHERE x = [cell reference]". I know this question has been asked repeatedly in different forms but it seems that connecting with Excel 2007 through an ODBC connection doesn't behave the way others do. I've tried using the following syntax:
WHERE A.EMPLID = '" & Range("B1") & "'
A.EMPLID is my SQL field name
B1 is the cell where I enter my A.EMPLID filter value
If I manually edit the query (as below) it returns a perfect set of data. I'm just trying to avoid having to manually edit the query every time I want a new data set.
WHERE A.EMPLID = '81726354'
The query with the cell reference doesn't cause any errors but it doesn't return any results either. I've also named the cell as a range but don't know how I'd reference that in a SQL query (if that's even possible). I'm trying to avoid doing it with VBA.
WHERE A.EMPLID = '" & Range("B1") & "'
A.EMPLID is my SQL field name
B1 is the cell where I enter my A.EMPLID filter value
If I manually edit the query (as below) it returns a perfect set of data. I'm just trying to avoid having to manually edit the query every time I want a new data set.
WHERE A.EMPLID = '81726354'
The query with the cell reference doesn't cause any errors but it doesn't return any results either. I've also named the cell as a range but don't know how I'd reference that in a SQL query (if that's even possible). I'm trying to avoid doing it with VBA.