Solved

Excel 2016 ADO connection and Access 2016

Posted on 2016-09-07
2
394 Views
Last Modified: 2016-09-24
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

0
Comment
Question by:hindersaliva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 41788553
Anytime you get an error you should post full details of that error (and a screenshot of the error message is good too). Otherwise we're just guessing.

Do you mean if the CONNECTION is open you get an error? That would seem to be the case, since you can definitely connect to an "open" Access database (i.e. one open in the Access window).

Also:

If the connection is open, why close it just to reopen it? It would seem a more logical flow would be:

If Not CBool(objConn.State And adStateOpen) Then
   Set objConn = New ADODB.Connection
   objConn.Open "Provider = Microsoft.ACE.OLEDB.12.0;" & "Data Source="C:\MyTest\Database\test.accdb"
End If
0
 

Author Closing Comment

by:hindersaliva
ID: 41813627
I couldn't repeat the problem. It did not happen again.
However, Scott's advice is good.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

739 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