Share via

-2147467259: Unrecognized database format

Anonymous
2016-02-19T03:47:03+00:00

I am working with MS Word 2010 and Access 2010.

I am trying to import forms into an Access 2010 table.  I am receive this error:

-2147467259: Unrecognized database format 'C:\Users\username\Desktop\Working On\WC\Test Data\TestForImportingWord.accdb'.

I have the following references checked:

Microsoft Access 14.0 Object Library,

Microsoft Word 14.0 Object Library, and

Microsoft Active Data Objects 6.1 Library

Here is the code:

Sub GetWordData()

Dim appWord As Word.Application

Dim doc As Word.Document

Dim cnn As New ADODB.Connection

Dim rst As New ADODB.Recordset

Dim strDocName As String

Dim blnQuitWord As Boolean

On Error GoTo ErrorHandling

strDocName = "C:\Users\username\Desktop\Working On\WC\Test Data" & _

    InputBox("Enter the name of the Indirect Assessment File " & _

    "you want to import:", "Import Assessment")

Set appWord = GetObject(, "Word.Application")

Set doc = appWord.Documents.Open(strDocName)

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\username\Desktop\Working On\WC\Test Data\TestForImportingWord.accdb"

rst.Open "tblEmployees", cnn, _

    adOpenKeyset, adLockOptimistic

With rst

    .AddNew

    !Name = doc.FormFields("Name").Result

    !Street = doc.FormFields("Street").Result

    !City = doc.FormFields("City").Result

    !State = doc.FormFields("State").Result

    !Zip = doc.FormFields("Zip").Result

    !Phone = doc.FormFields("Phone").Result

    .Update

    .Close

End With

doc.Close

If blnQuitWord Then appWord.Quit

cnn.Close

MsgBox "Data Imported!"

Cleanup:

Set rst = Nothing

Set cnn = Nothing

Set doc = Nothing

Set appWord = Nothing

Exit Sub

ErrorHandling:

Select Case Err

Case -2147022986, 429

    Set appWord = CreateObject("Word.Application")

    blnQuitWord = True

    Resume Next

Case 5121, 5174

    MsgBox "You must select a valid Word document. " _

        & "No data imported.", vbOKOnly, _

        "Document Not Found"

Case 5941

    MsgBox "The document you selected does not " _

        & "contain the required form fields. " _

        & "No data imported.", vbOKOnly, _

        "Fields Not Found"

Case Else

    MsgBox Err & ": " & Err.Description

End Select

GoTo Cleanup

End Sub

Does anyone know what I am doing wrong?

Thanks,

Deb

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
2016-02-21T22:46:59+00:00

Hello all,

I figured it out.  I just called the tables separately and then after I populated the first table, I pulled the last record number, populated it in a variable, and then added that variable into the second table's EmployeeID field.

rstEmployee.Open "tblEmployees", cnn, adOpenKeyset, adLockOptimistic

rstWorkInfo.Open "tblWorkInfo", cnn, adOpenKeyset, adLockOptimistic

'Add new record to each table and copy fields from Word document

               

    With rstEmployee

        .AddNew

        !Name = doc.FormFields("Name").Result

        !Street = doc.FormFields("Street").Result

        !City = doc.FormFields("City").Result

        !State = doc.FormFields("State").Result

        !Zip = doc.FormFields("Zip").Result

        !Phone = doc.FormFields("Phone").Result

        .Update

    End With

    rstEmployee.Close

    Set rstEmployee = Nothing

    lngEmployeeID = DLast("[EmployeeID]", "tblEmployees")

    With rstWorkInfo

        .AddNew

        !EmployeeID = lngEmployeeID

        !Salary = doc.FormFields("Salary").Result

        !Title = doc.FormFields("Title").Result

        !Active = doc.FormFields("Status").Result

        .Update

    End With

    rstWorkInfo.Close

    Set rstWorkInfo = Nothing

I would not expect this to work reliably, because DLast doesn't really return the "last", or most recently added, value from a table.  It's fairly arbitrary unless there's a explicit ordering in place for the records it's looking at.  Apparently it has worked for you so far, maybe because Access used the default primary-key ordering of the table as a matter of convenience, but I wouldn't want to rely on it, and there's no guarantee that it will continue to bring back the EmployeeID you just added.  This would be a better approach:

'------ start of code ------

    With rstEmployee

        .AddNew

        !Name = doc.FormFields("Name").result

        !Street = doc.FormFields("Street").result

        !City = doc.FormFields("City").result

        !State = doc.FormFields("State").result

        !Zip = doc.FormFields("Zip").result

        !Phone = doc.FormFields("Phone").result

        .Update

        ' Get the employee ID from the record we just added.

        .Bookmark = .LastModified

        lngEmployeeID = !EmployeeID

    End With

    rstEmployee.Close

    Set rstEmployee = Nothing

    With rstWorkInfo

        .AddNew

        !EmployeeID = lngEmployeeID

        !Salary = doc.FormFields("Salary").result

        !Title = doc.FormFields("Title").result

        !Active = doc.FormFields("Status").result

        .Update

    End With

    rstWorkInfo.Close

    Set rstWorkInfo = Nothing

'------ end of code ------

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2016-02-19T04:29:49+00:00

I am working with MS Word 2010 and Access 2010.

[...]

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\username\Desktop\Working On\WC\Test Data\TestForImportingWord.accdb"

To read an .accdb file, your connection string will have to specify the ACE provider:

    Provider=Microsoft.ACE.OLEDB.12.0

Was this answer helpful?

0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-02-19T12:02:26+00:00

    Daniel,

    Even though I have the answer, I still want to answer your questions for future people looking at this.

    Code is a module in the database.

    The error was running against the provider piece of the code but I couldn't find what to replace it with.

    I can open the database fine without the error.

    Thank you for responded.

    Debra Ann

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-02-19T12:00:42+00:00

    Hi Dirk,

    Thank you, that was it.

    Debra Ann

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-02-19T04:11:17+00:00

    Where is this code located/run?

    What line is generating the error?

    Can you open the database in question manually without getting the error?  I suspect it is corrupted.

    Was this answer helpful?

    0 comments No comments