ADODB与ACCDB文件的连接-无法识别的数据库格式错误 [英] ADODB connection to ACCDB file -- unrecognized database format error

查看:256
本文介绍了ADODB与ACCDB文件的连接-无法识别的数据库格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的文件:

I have a file like this:

strPath = "S:\HR\Forms\forms_database.accdb"

我正在通过WORD adodb.connection

I am connecting to it through an WORD adodb.connection

我的数据库应该是其他扩展名吗? MDB还是什么?

should my database be a different extension ? MDB or something?

尝试连接时出现此错误:

I am getting this error when it tries to connect:

unrecognized database format 's:...............accdb'

这是怎么回事?

这是完整的代码:

Sub TransferShipper()

  'Transfer new shipping company record to

  'Shippers table in Northwind database.

  Dim cnn As ADODB.Connection
  Dim strConnection As String
  Dim strSQL As String
  Dim strPath As String
  Dim doc As Word.Document
  Dim strCompanyName As String
  Dim strPhone As String
  Dim bytContinue As Byte
  Dim lngSuccess As Long
  Set doc = ThisDocument
  On Error GoTo ErrHandler

  strCompanyName = Chr(39) & doc.FormFields("txtCompanyName").Result & Chr(39)
  strPhone = Chr(39) & doc.FormFields("txtPhone").Result & Chr(39)
  'Confirm new record.
  bytContinue = MsgBox("Do you want to insert this record?", vbYesNo, "Add Record")
  Debug.Print bytContinue
  'Process input values.
  If bytContinue = vbYes Then
    strSQL = "INSERT INTO vacation " _
     & "(title, department) " _
     & "VALUES (" _
     & strCompanyName & ", " _
     & strPhone & ")"
    Debug.Print strSQL
    'Substitute path and connection string with DSN if available.
    strPath = "S:\HR\Forms\forms_database.accdb"
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" _
     & "Data Source = " & strPath
    Debug.Print strConnection
    Set cnn = New ADODB.Connection
    cnn.Open strConnection
    cnn.Execute strSQL, lngSuccess
    cnn.Close
    MsgBox "You inserted " & lngSuccess & " record", _
     vbOKOnly, "Error Added"
    doc.FormFields("txtCompanyName").TextInput.Clear
    doc.FormFields("txtPhone").TextInput.Clear
  End If
  Set doc = Nothing
  Set cnn = Nothing
  Exit Sub
ErrHandler:
  MsgBox Err.Number & ": " & Err.Description, _
   vbOKOnly, "Error"
  On Error GoTo 0
  On Error Resume Next
  cnn.Close
  Set doc = Nothing
  Set cnn = Nothing
End Sub

推荐答案

尝试使用ACE OLEDB 12.0作为数据库版本.

Try ACE OLEDB 12.0 as the db version.

"Provider=Microsoft.ACE.OLEDB.12.0"

这篇关于ADODB与ACCDB文件的连接-无法识别的数据库格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆