Hi all,
I keep getting the following error:-
Run-time error '3367':
Cannot Append. An object with that name already exisits in the collection.
This occurs when I use TableDefs.Append.
The situation is this. I'm developing a module to create a table. Passed ot the module is a string with the new table's name and a string array with fields name and type. Currently as I am testing I am only creating a table with the name Test and fields test0 to test4, all type dbText.
Currently my module checks to see if the table test already exists. If it does it deletes it and refreshes TableDefs. It then creates the new table and adds the fields. This first field (test0) is always added without issue, the second field (test1) is always when the code fails at TableDefs.Append.
Here is the code:-
Many thans in advance for any help
Matt
I keep getting the following error:-
Run-time error '3367':
Cannot Append. An object with that name already exisits in the collection.
This occurs when I use TableDefs.Append.
The situation is this. I'm developing a module to create a table. Passed ot the module is a string with the new table's name and a string array with fields name and type. Currently as I am testing I am only creating a table with the name Test and fields test0 to test4, all type dbText.
Currently my module checks to see if the table test already exists. If it does it deletes it and refreshes TableDefs. It then creates the new table and adds the fields. This first field (test0) is always added without issue, the second field (test1) is always when the code fails at TableDefs.Append.
Here is the code:-
Code:
Public Sub CreateTable(strTblName As String, strTblFields() As String)
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Dim intCount As Integer
Dim boolTableExists As Boolean
Set db = CurrentDb
boolTableExists = False
intCount = 0
Do While boolTableExists = False And intCount <= db.TableDefs.Count - 1
If db.TableDefs(intCount).Name = strTblName Then boolTableExists = True
intCount = intCount + 1
Loop
If boolTableExists Then db.TableDefs.Delete (strTblName)
db.TableDefs.Refresh
Set tbl = db.CreateTableDef(strTblName)
intCount = 0
Do While intCount <= UBound(strTblFields, 1)
tbl.Fields.Append tbl.CreateField(strTblFields(0, intCount), strTblFields(1, intCount))
db.TableDefs.Append tbl
db.TableDefs.Refresh
intCount = intCount + 1
Loop
End Sub
Many thans in advance for any help

Matt