
Attaching a dBase III table to Access 2000 via ADO
Using VB6, SP3, mdac 2.1 latest, OFF2K installed. Win98SE
You may wish to look at the code below (sample from MS Office 2000 VB prg
guide), but...
The following snip gives an error indicating the path/filename to the
external dbf (XYZ.dbf) could not be found.
Both are correct.
Any hints?
Thanks, GW
' Start snip
Dim catDB As ADOX.Catalog
Dim tblLink As ADOX.Table
Set catDB = New ADOX.Catalog
' Open a Catalog object on the database
' in which to create the link.
catDB.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & strTargetDB & ";" & _
"Jet OLEDB:Engine Type=5;"
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 = strLinkTblName
Set .ParentCatalog = catDB
' Set the properties to create the link.
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB:Link Datasource") = App.Path & "\" & "XYZ.dbf"
.Properties("Jet OLEDB:Link Provider String") = "dBASE III"
'///(sLinkProviderString)
.Properties("Jet OLEDB:Remote Table Name") = sExternalTableName
End With
' Create the new linked table by adding the
' Table object to the Tables collection.
catDB.Tables.Append tblLink
Set catDB = Nothing
'End snip
Quote:
> Hi
> I'm currently converting my DAO code to ADO and are struggling to attach a
> dbase III file to an Access 2000 mdb through code. Below was my DAO 3.6
code
> whereby I connected. I am short on time and need to have this function in
> ADO. Any help would be highly appreciated.
> Public Function AttachTable(ByVal pTarget As String, ByVal pAlias As
String,
> ByVal pConnect As String, ByVal pPath As String) As Boolean
> Dim tExist As Boolean
> Dim tDbase As dao.Database
> Dim tLinked As New dao.TableDef
> Dim tLink As dao.TableDef
> Dim tName As String
> Dim tPath As String
> AttachTable = False
> Set tDbase = OpenDatabase(pTarget)
> ''remove the attachment if it exists
> For i = 0 To tDbase.TableDefs.Count - 1
> If tDbase.TableDefs(i).name = pAlias Then
> tDbase.TableDefs.Delete pAlias
> tDbase.TableDefs.Refresh
> tDbase.QueryDefs.Refresh
> DoEvents
> Exit For
> Else
> End If
> Next i
> tName = (TrimFile(pPath))
> tPath = TrimPath(pPath)
> tLinked.SourceTableName = tName
> tLinked.Connect = pConnect & tPath
> tLinked.name = pAlias
> tDbase.TableDefs.Append tLinked
> tDbase.TableDefs.Refresh
> tDbase.QueryDefs.Refresh
> AttachTable = True
> tDbase.Close
> Exit Function
> Amien Crombie - Cape Town