We help IT Professionals succeed at work.
Get Started

Access 2010 ADODB Connection problem

Last Modified: 2012-05-10
Hi. I am using the following code to connect to a database but on the line marked "Error here" I am getting an error saying unregognized database format. I have attached a screenshot showing the error as well as the properties of my database

Sub getProjectDescFromAccess()
    Const projectIDColumn = "A"
    Const projectDescColumn = "J"
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sSQL As String, strConn
    Dim looper As Long
    Dim cellPointer As Variant
    Dim MYDOC_DIR As String
    Dim DATABASE_PATH As String
    MYDOC_DIR = Environ("userprofile") & "\Documents"
    DATABASE_PATH = MYDOC_DIR & "\Database1.accdb"
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DATABASE_PATH & ";Persist Security Info=False"
    Set cnn = New ADODB.Connection
    cnn.Open strConn  'Error here
    For X = 2 To Range(projectIDColumn & Rows.Count).End(xlUp).Row
    Set cellPointer = Worksheets("Charges Form").Range(projectIDColumn & X)
    'If you project number field is text use this sSQL
    sSQL = "SELECT tblBank.* FROM tblBank WHERE(((tblBank.NMBR)='" & cellPointer & "'));"
    Set rs = New ADODB.Recordset
    rs.Open sSQL, cnn, adOpenStatic, adLockOptimistic
    If Not IsNull(rs.Fields("NMBR").Value) Then
       Range(projectDescColumn & looper) = rs.Fields("NMBR").Value
    End If
    Set rs = Nothing
    Next X
    Set cnn = Nothing
End Sub Screenshot
Watch Question
This problem has been solved!
Unlock 1 Answer and 15 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE