简体   繁体   中英

Why do some of my SQL queries work in a VBA script and some don't?

I'm trying to query an MDB file from an excel VBA script. I know I'm connecting okay because I can get some queries to successfully return results.

Consider 2 queries - fairly simple and similar:

SELECT DESCRIPTION from MS where CATALOG='3RV1915-6AB'

and

SELECT DESCRIPTION from MS where MANUFACTURER='100-2SIEMENS'

Both queries refer to the same record in the MDB table and work fine in Access. The second query also works from Excel VBA code, but the first throws this error:

Err.Number = -2147467259

Both CATALOG and MANUFACTURER columns are Short Text fields (though the lengths are different: 60 and 24 respectively). All other MDB Field settings are identical.

I've run out of ideas of how to debug this behavior. How can I fix this?

So - apparently I've discovered that "CATALOG" is a key word being used as a field name...

SO - it needs to be "[CATALOG]" to force the interpretation to be the field name. That solves my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM