Create external database

R

Ronald

Hi all.

I need to create an external database (file). On a site I found this code:
------------------------------------------------------
Function CreateLinkedExternalTable(strTargetDB As String, strProviderString
As String, strSourceTbl As String, strLinkTblName As String) As String

'strTargetDB = Source Database Name
'strProviderString = Not used, currently hard coded
'strSourceTbl = Source Table name in the database we are linking too.
'strLinkTblName = Table name we would like to see in the Access Database.
Dim catDB As ADOX.Catalog
Dim tblLink As ADOX.Table

Set catDB = New ADOX.Catalog
'Open a Catalog on the database in which to create the link.
[catDB].ActiveConnection = "Provider=Microsoft.Jet.OLEDB.12.0;Data
Source=" & "C:\Database\Test.accdb" 'strSourceDBFile
If ([catDB].ActiveConnection.State <> acObjStateOpen) Then GoTo ErrHandler

Set tblLink = New ADOX.Table
With [tblLink]
'Name the new Table and set its ParentCatalog property to the open
Catalog to allow access to the Properties collection.
.Name = strSourceTbl
Set .ParentCatalog = catDB
'Set the properties to create the link.
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB:Link Provider String") =
"Provider=ODBC;DSN=TestODBC;DATABASE=TestDB;UID=admin;Password="
'strProviderString
.Properties("Jet OLEDB:Remote Table Name") = strLinkTblName
End With

'Append the table to the Tables collection.
On Error Resume Next 'If table doesn't exist continue.

[catDB].Tables.Delete strSourceTbl

On Error GoTo ErrHandler

[catDB].Tables.Append tblLink
Set catDB = Nothing

Exit Function

ErrHandler:
MsgBox Err.Number & " " & Err.Description
Set catDB = Nothing

End Function
------------------------------------------------------
But when I test it I get error 3706 (Provider cannot be found. It may not be
properly installed.) on line: [catDB].ActiveConnection =
"Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" & "C:\Database\Test.accdb"
'strSourceDBFile

It looks like '12.0' is not available but when I use '4.0' I get
'Unrecognized database format' error.
Is it possible to create an Access 2007 format database?

Thanks for your help,

Ronald.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top