Share via

Recordset error Unrecognized database format

Anonymous
2012-11-30T05:16:21+00:00

I am working with a recordset problem in Access 2010. Below is the code I have so far and I get an error where commented. The error I get is: Run-time error '-2147467259(80004005)':Unrecognized database format 'C:\Users\fc\desktop\MyRecordsetDB.accdb'.

I have the following References active:

Visual Basic for Applications

Microsoft Access 14.0 Object Library

OLE Automation

Microsoft ActiveX Data Objects 2.6 Library

The database was created using Access 2010.

I have not been able to check any of the rest of the code so I don't know if there are any other errors.

Code:

Private Sub Form_Load()

Dim cnn1 As ADODB.Connection

Dim rs As ADODB.Recordset

Dim strCnn As String

'create string var to hold new information

Dim strID As String, strLot As String, strAM As String, strPM As String

'variable to hold path to current db  name

Dim strPath As String

strPath = Application.CurrentProject.Path & "" & Application.CurrentProject.Name

Dim mydb As String

mydb = strPath

'MsgBox strPath  for testing purposes only but shows correct path

' Open a connection.

    Set cnn1 = New ADODB.Connection

    strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb

    /////////////Error occurs on next line/////////////////////////////

    cnn1.Open strCnn

' Open contact table.

    Set rs = New ADODB.Recordset

    rs.CursorType = adOpenKeyset

    rs.LockType = adLockOptimistic

    rs.Open Source:="Select * from tblTest"

'get the new record data

        'Use inputbox to get info for new record

        strID = Val(InputBox("Enter ID", "Manager ID Number"))

        strLot = InputBox("Enter lot number", "Lot Number")

        strAM = InputBox("Does this employee work the AM shift? vbnewLine Enter Yes or No", "Shift Assignment")

        strPM = InputBox("Does this employee work the PM shift? vbnewLine Enter Yes or N0", "Shift Assignment")

        rs.AddNew

        rs!mgrID = strID

        rs!mgrID = strLot

        rs!mgrID = strAM   'update the Y/N field in the recordset to Yes or No

        rs!mgrID = strPM   'update the Y/N field in the recordset to Yes or No

' Show the newly added data.

        MsgBox "New manager ID: " & rs!mgrID & " has been successfully added"

'close connections

    rs.Close

    cnn1.Close

End Sub

Thank you for your help

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-11-30T23:27:40+00:00

You show this:

strPath = Application.CurrentProject.Path & "" & Application.CurrentProject.Name

Which means you are trying to use the Current database.  So, just change your ADO connection to be using

Set cnn = CurrentProject.Connection

as you should be using that for any connections within the current database that the code is in.  Don't use outside referencing or you can end up with problems.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful