Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel 2016 ADO connection and Access 2016

Posted on 2016-09-07
2
Medium Priority
?
824 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

618 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