Coding⏱️ 2 min read📅 2026-06-11

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

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

Quick Answer: Check ConnectionString properties and ensure correct DSN, UID, Password, and server settings.

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

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

Alternative Advanced Fix

    💡 Conclusion

    Did this fix your problem?

    If not, try searching for specific error codes.

    🔍 Search Error Database

    ❓ Frequently Asked Questions