2010-07-23 10 views
5

Tengo un archivo de la siguiente manera:conexión ADODB a ACCDB archivo - Error no reconocido formato de base de datos

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

Estoy conectando a ella a través de un PALABRA adodb.connection

debe ser mi base de datos una extensión diferente? MDB o algo así?

estoy recibiendo este error cuando intenta conectarse:

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

lo que está pasando aquí?

aquí está el código completo:

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 

Respuesta

9

Try ACE OLEDB como la versión 12.0 dB.

"Provider=Microsoft.ACE.OLEDB.12.0" 
+0

eres el hombre muchas gracias! –

Cuestiones relacionadas