DEV Community

TechFixDocs
TechFixDocs

Posted on • Originally published at techfixdocs.my.id

How to Fix: VBA Automation error when querying database through ODBC

VBA automation error when querying database through ODBC, error details and solution provided.

The Problem

The error you are experiencing when querying your database through ODBC is due to the incorrect connection string. The original code used the 'Connection' object, which is not compatible with the new code that uses the 'ConnectionString' property.This issue affects users who have modified their VBA code to use the 'ConnectionString' property and are now experiencing errors when trying to connect to their ODBC database.
🔍 Why This Happens

                The primary reason for this error is the incorrect usage of the 'Connection' object versus the 'ConnectionString' property. The original code used the 'CreateObject' method to create a new instance of the 'ADODB.Connection' class, whereas the new code uses the 'ConnectionString' property to establish a connection.Another possible cause could be the incorrect database credentials or the ODBC DSN details.

            🛠️ Step-by-Step Verified Fixes

                Correcting the Connection String

                    Step 1: Change the line `Set Connection = CreateObject(



                Alternative Advanced Fix




            💡 Conclusion
Enter fullscreen mode Exit fullscreen mode

Full step-by-step guide with screenshots: Read the complete fix here

Found this helpful? Check out more verified tech fixes at TechFixDocs

Top comments (0)