Amy Rollinson
Amy Rollinson

Reputation: 1

Run-time error '-2147217900 (80040e14)' sytax error (missing operatory) in SQL query expression in VBA

I am building SQL queries in VBA, and the following returns an error:

stSQLstring = "SELECT * FROM [" & sheetName & "$]
               WHERE [" & headerName & "] in (" & stNodes & ");"

Debug.Print stSQLstring gives:

SELECT * FROM [sheetName$]
WHERE [headerName] in ('3','4','5','6','16','45','64','65','67','71','76','79','80','86','89','103','115','116','124','142','145','160');

I am then using ACE.OLEDB to query an external workbook (I think this part is fine as it works with other SQL statements, just not this one).

I would be really grateful for you help!

Upvotes: 0

Views: 505

Answers (1)

user6432984
user6432984

Reputation:

You shouldn't use the single quotes when working with numbers.

SELECT * FROM [sheetName$] WHERE [headerName] in (3,4,5,6,16,45,64,65,67,71,76,79,80,86,89,103,115,116,124,142,145,160);

Upvotes: 1

Related Questions