Attaching a dBase III table to Access 2000 via ADO 
Author Message
 Attaching a dBase III table to Access 2000 via ADO

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



Mon, 22 Jul 2002 03:00:00 GMT  
 Attaching a dBase III table to Access 2000 via ADO
Same problem using:

VB6, SP3, mdac 2.1 latest, and Off2K installed.

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 (Access 2K)
' 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



Wed, 24 Jul 2002 03:00:00 GMT  
 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



Wed, 24 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linking a dBase III table to an Access 2000 database - won't open

2. Import dBase III files to Access 2000 with ADO

3. ADO problem with database operations on dBase III tables

4. NEED HELP IMPORTING DBASE III INTO ACCESS VIA VB 5

5. ADO problem with database operations on dBase III tables

6. ADO link dBASE III table syntax

7. saving Access Tables to dbase III file format

8. Converting from Access tables to dBase III files

9. Converting from Access tables to dBase III files

10. Moving records from a dBase file to an Access 2000 Table

11. connecting to dBase III dbf table with VB 6

12. creating dbase III tables in vb5.0

 

 
Powered by phpBB® Forum Software