Using ADO to connect to a database: Factors preventing connection

Posted on 2009-12-23
Last Modified: 2013-12-05
Dear Experts,

What could be causing this textbook example form from connecting to the Northwind database whose file path is correct?

I've just checked the reference library selections, the file type of both Databases and the code. I get a 424 error which says it cannot connect tot the database.

Line 5 is highlighted as the problem.

Option Compare Database

Private Sub Form_Load()

Dim remoteConnection As New ADODB.Connection

Dim rsProducts As New ADODB.Recordset




End Sub

Private Sub Form_Unload(Cancel As Integer)



End Sub

Public Sub Disconnect()

    On Error GoTo ConnectionError





Exit Sub


MsgBox "There was an error closing the databse." & _

    Err.Number & ", " & Err.Description


End Sub

Private Sub Connect()

    On Error GoTo ConnectionError


    With remoteConnection

        .Provider = "Microsoft.ACE.OLEDB.12.0"

        .Open "C:\Users\S B\Documents\Databases\Northwind.accdb"


    End With

    Exit Sub




    MsgBox "There was an error connecting to the database. " & _

        Chr(13) & Err.Number & ", " & Err.Description


End Sub

Public Sub SetRecordset()

Dim sql As String

On Error GoTo DbError

sql = "select * from Products"

rsProducts.CursorType = adOpenKeyset

rsProducts.LockType = adLockReadOnly

rsProducts.Open sql, remoteConnection, _

    , , adCmdText


    If rsProducts.EOF = False Then

    'Using three different techniques to access items in a recordset

    Me.txtProductID = rsProducts!ID

    Me.txtProductCode = rsProducts.Fields.Item("Product Code")

    Me.txtProductName = rsProducts.Fields.Item(3)


End If

Exit Sub


MsgBox "There was an error retrieving information " & _

       "From the database." _

       & Err.Number & ", " & Err.Description


End Sub

Open in new window

Question by:9XqUwH3S
    LVL 14

    Accepted Solution


    Check to see that ADO is referenced for this statement.
    Dim remoteConnection As New ADODB.Connection

    The code below does not appear correct.  The Connect and SetRecordset are "hanging".  
    Dim rsProducts As New ADODB.Recordset


    Author Comment

    Thank you for the gift of your comment, Bill Denver. Merry Christmas.

    Yes, that line is in my project.

    Removing all of the debug code seems to have worked. I'm in process of finishing this to confirm what the solution turns out to be.

    I'll let you know. It might be 48 hours from now, but I look forward to telling what the solution was.


    Author Comment

    Could you clarify what you mean by "hanging" in regard to line 22 and 23. How would I complete that?

    Author Closing Comment

    Thank you. The book example appears to not work. I am satisfied to move on because I have had success with my project for which the example was intended to help me accomplish,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now