How to Check for the ODBC Driver in VBA

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Email

Being able to check for the status of an ODBC driver through a DSN connection using Visual Basic for Applications can save you time by ending your program if the ODBC connection doesn't exist. VBA is used in Microsoft Office applications to automate routine tasks otherwise done manually. In Excel, you can use VBA to automate the process of importing data from an Access database by using an ODBC connection.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Launch Microsoft Office Excel. Click the "Developer" tab followed by "Visual Basic." Click the "Insert" menu and then "Module" to insert a new module.

  2. 2

    Create a new sub procedure:

    Private Sub checkODBC()

  3. 3

    Create the object variables you will use to check the ODBC driver:

    Dim adoCNN As ADODB.Connection
    Dim can Connect As Boolean
    Set adoCNN = New ADODB.Connection
  4. 4

    Define the ODBC name, login name, and password:

    adoCNN.Open "DSN Name", "username", "password"
  5. 5

    Check the state of the ODBC driver:

    If adoCNN.State = adStateOpen Then
        can Connect = True
    End If
  6. 6

    Display a message box informing the user of the state of the ODBC connection:

    If can Connect Then
        MsgBox "ODBC connection is ready!"
        MsgBox "ODBC connection is not ready!"
    End If

    End Sub

  7. 7

    Press "F5" to run the procedure.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.