I have a file like this:
strPath = "S:\HR\Forms\forms_database.accdb"
I am connecting to it through an WORD adodb.connection
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'
what's going on here?
here's the entire code:
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
The problem with an unrecognized database can be solved after converting it to an earlier database format. It is also not difficult to do: Go to the database and click on the Tools tab. Next, select Convert Database from the list, and then select the tab to access the file format version.
As per user instances, the error occurs when accessing tables or any form linked to a table. You may also experience it when using the 'OpenDatabase' method (DAO) to open a db from Visual Basic code. Whatever may be the situation, the 'unrecognized database format' error turns the database inaccessible or corrupted.
Under File Types, click Save Database As. Under Save Database As, do one of the following: To save a copy of the database in an . mdb format that can be opened by using Access 2002 or Access 2003, click Access 2002 - 2003 Database (*.
Try ACE OLEDB 12.0 as the db version.
"Provider=Microsoft.ACE.OLEDB.12.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With