Y
Your name
I have a simple problem here in Access 2003.
I import 18 .csv files into 18 unique tables.. I then programatically want
to add an index to each of the 18 tables. The code creates the index for
the first table then gives a message on the 2nd thru 18th table that I try
to create the index for.
The message: Run-time error: '3367':
Object is already in collection. Cannot append.
I am trying to create a "TradeDateIndex" index on each of the 18 tables.
The code:
Public Sub CreateIndexOnStockTables()
Dim tbl As New ADOX.Table
Dim index As New ADOX.index
Dim cat As New ADOX.Catalog
Set cat = CreateObject("ADOX.Catalog")
cat.ActiveConnection = CurrentProject.Connection
For Each tbl In cat.Tables
If tbl.Type = "TABLE" Then
If (UCase$(Left$(tbl.Name, 10)) = "STOCKTABLE") Then
With tbl
index.Name = "TradeDateIndex"
index.Columns.Append "Date"
tbl.Indexes.Append index
End With
End If
End If
Next
Set tbl = Nothing
Set index = Nothing
Set cat = Nothing
End Sub
I have a reference set to "Microsoft ADO Ext. 2.8 for DDL and security.
Thanks in advance for your help.
I import 18 .csv files into 18 unique tables.. I then programatically want
to add an index to each of the 18 tables. The code creates the index for
the first table then gives a message on the 2nd thru 18th table that I try
to create the index for.
The message: Run-time error: '3367':
Object is already in collection. Cannot append.
I am trying to create a "TradeDateIndex" index on each of the 18 tables.
The code:
Public Sub CreateIndexOnStockTables()
Dim tbl As New ADOX.Table
Dim index As New ADOX.index
Dim cat As New ADOX.Catalog
Set cat = CreateObject("ADOX.Catalog")
cat.ActiveConnection = CurrentProject.Connection
For Each tbl In cat.Tables
If tbl.Type = "TABLE" Then
If (UCase$(Left$(tbl.Name, 10)) = "STOCKTABLE") Then
With tbl
index.Name = "TradeDateIndex"
index.Columns.Append "Date"
tbl.Indexes.Append index
End With
End If
End If
Next
Set tbl = Nothing
Set index = Nothing
Set cat = Nothing
End Sub
I have a reference set to "Microsoft ADO Ext. 2.8 for DDL and security.
Thanks in advance for your help.