PDA

Click to See Complete Forum and Search --> : FoxPro table error


DrewDog_21
Jan 3rd, 2000, 06:36 AM
Hi folks, I am trying to create a foxpro table at runtime to which I will add some data at a later point. The table needs to have the same structure as another Access table in teh TableDefs collection.

I have some code like this that is based on an example I found on microsoft.com

Private Sub Form_Load()

Dim dbs As Database
Dim tdfNewExternalDatabase As TableDef
Dim tdfTestNewTable As TableDef
Dim fldContactName As Field
Dim fldPhoneNumber As Field
Dim qdfInsertRecords As QueryDef
Dim rstCheckRecordCount As Recordset
Dim intNumRecords As Integer

Dim Name As TableDef

Set dbs = OpenDatabase
"C:\FoxPro\Data\db1.mdb", False, False)

Set tdfNewExternalDatabase = dbs.CreateTableDef("AccessTable")

Set fldContactName = tdfNewExternalDatabase.CreateField("Contact_Name", dbText)
fldContactName.Size = 30

Set fldPhoneNumber = tdfNewExternalDatabase.CreateField("Phone_Number", dbText)
fldPhoneNumber.Size = 25

tdfNewExternalDatabase.Fields.Append fldContactName
tdfNewExternalDatabase.Fields.Append fldPhoneNumber

dbs.TableDefs.Append tdfNewExternalDatabase

DoCmd.TransferDatabase acExport, _
"dBase IV", "C:\FoxPro\Data", acTable, _
"AccessTable", "FoxTable"

dbs.TableDefs.Delete "AccessTable"

Set tdfTestNewTable = dbs.CreateTableDef("FoxTable")

tdfTestNewTable.Connect = _
"dBase IV;DATABASE=C:\FoxPro\Data;"

tdfTestNewTable.SourceTableName = "FoxTable"
dbs.TableDefs.Append tdfTestNewTable

End Sub

(not all of the lines would fit in the text box so there are some _'s missing)

The line of code
tdfTestNewTable.SourceTableName = "FoxTable"
dbs.TableDefs.Append tdfTestNewTable

gives me the error that the object FoxTable can't be found. According to the example code, everything is right.

Any ideas?

Thanks

Andrew