HalloweenWeed
Member
- Local time
- Today, 13:06
- Joined
- Apr 8, 2020
- Messages
- 220
Hello,
I'm trying to write vba that copies fields across TableDefs - I just want to be able to do that, as a learning exercise. I have written the following code to do so, but I get Error 3367: Cannot append. An object with that name already exists in the collection.
In the line:
The code skips the first Field: "ID" (key), as it is created in the table already, using the normal method during table creation.
I use Field2 because some of my Fields are complex data type. I have Googled this, but I don't see any info about this particular problem.
I stepped it through, and on the first execution of "fldsWrit.Append fld2" the FieldName = "calc today". There is no "calc today" field in the local table ShrptData_tbl. Table ExcelIR_Stats is a table linked to an Excel file table, generated from a .iqy query to a Sharepoint List (and thus the complex data types). I cannot modify the Sharepoint list.
Can anybody shed light on why I am getting this error, or what to do to mitigate it?
I'm trying to write vba that copies fields across TableDefs - I just want to be able to do that, as a learning exercise. I have written the following code to do so, but I get Error 3367: Cannot append. An object with that name already exists in the collection.
In the line:
Code:
fldsWrit.Append fld2
Code:
Dim FieldName As String, Msg As String
Dim fld As Field, fld2 As Field2
Dim fldsGet As Fields, fldsWrit As Fields
Dim obj As AccessObject, dbs As Object
Dim tdfXl As DAO.TableDef, tdfAcs As DAO.TableDef
Dim tblXl As DAO.Recordset, tblAcs As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set dbs = Application.CurrentData
' Set tblXl = CurrentDb.OpenRecordset("ExcelIR_Stats", dbOpenTable, dbReadOnly)
' Set tblAcs = CurrentDb.OpenRecordset("ShrptData_tbl", dbOpenTable)
Stop
Set tdfXl = DB.TableDefs("ExcelIR_Stats")
Set tdfAcs = DB.TableDefs("ShrptData_tbl")
Set fldsGet = tdfXl.Fields
Set fldsWrit = tdfAcs.Fields
For Each fld2 In fldsGet
FieldName = fld2.Name
If FieldName <> "ID" Then
fldsWrit.Append fld2
End If
Next fld2
I use Field2 because some of my Fields are complex data type. I have Googled this, but I don't see any info about this particular problem.
I stepped it through, and on the first execution of "fldsWrit.Append fld2" the FieldName = "calc today". There is no "calc today" field in the local table ShrptData_tbl. Table ExcelIR_Stats is a table linked to an Excel file table, generated from a .iqy query to a Sharepoint List (and thus the complex data types). I cannot modify the Sharepoint list.
Can anybody shed light on why I am getting this error, or what to do to mitigate it?