Avatar of hindersaliva
hindersaliva
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Excel 2016 ADO connection and Access 2016

When I run the following code a connection is made to an Access database. Ok.
However, if the database is open I get an error.

Is it possible to connect to an Access database with ADO like this AND have the database open?
If so how?

Thanks

Public objConn As New ADODB.Connection

Sub DBConnectionAccess()

    If CBool(objConn.State And adStateOpen) Then objConn.Close

    Dim strPathToDB As String
                 
    'open connection to Access database
    strPathToDB = "C:\MyTest\Database\test.accdb"
    objConn.Open "Provider = Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & strPathToDB

    Exit Sub

End Sub

Open in new window

Microsoft AccessMicrosoft Excel

Avatar of undefined
Last Comment
hindersaliva

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hindersaliva

ASKER
I couldn't repeat the problem. It did not happen again.
However, Scott's advice is good.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck