Skip to content
Advertisement

VBA throws an error when picking up cell values into SQL query

I get the following error when picking up values for my SQL from certain cells. However, when i hard code the values into the code, it works fine. so, it’s clearly something to do with the syntax of how i have written it.

I am looking to make this dynamic for several reasons and hoping someone can help me.

The error: The Microsoft Access Database Engine could not find the object “objectname”

Working code where the values are hard-coded:

Code that does not work:

Advertisement

Answer

I would advise putting your connection string value in a variable, and printing it (eg. debug.print myConnectionString) to perform a character per character comparison.

Also, you have single quotes surrounding your reference to sheet.range(“d1”)

Maybe those are the cause of your issue. You appear to have the same problem in the mySQL variable assignation.

Edit :

Maybe this could work :

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement