Hello,
I am attempting to go through ODBC views, re-attach the with a new name and creating the same index that I have placed on the original table. The following is the code that I am using. I keep getting an error:
Run-time error '3039'
Could not create index; Too many indexes already defined.
This occurs when I try to do the final table append. Any ideas?
Public Function ReIndex(table_name As String)
Dim db As Database
Dim tdf As TableDef
Dim tdf2 As TableDef
Dim idx As Index
Dim idx2 As Index
Dim strSrcTblName As String
Dim strTblName As String
Dim strTblCon As String
Stop
Set db = CurrentDb()
For Each tdf In db.TableDefs
If Mid(tdf.Name, 1, 4) <> "MSys" Then
If tdf.Indexes.Count > 0 Then
strSrcTblName = Mid$(tdf.SourceTableName, 5, Len(tdf.SourceTableName) - 4)
strTblName = tdf.Name
strTblCon = tdf.Connect
Set idx = tdf.Indexes(0)
Set tdf2 = db.CreateTableDef("Yo"
With tdf2
.Name = strTblName & "1"
.SourceTableName = strSrcTblName
.Connect = strTblCon
Set idx2 = tdf2.CreateIndex(idx.Name & "1"
With idx2
.Clustered = idx.Clustered
.Fields = idx.Fields
.IgnoreNulls = idx.IgnoreNulls
.Primary = idx.Primary
.Required = idx.Required
.Unique = idx.Unique
End With
.Indexes.Refresh
.Indexes.Append idx2
End With
db.TableDefs.Append tdf2
End If
End If
Next
End Function
Thanks
Graham Heath
I am attempting to go through ODBC views, re-attach the with a new name and creating the same index that I have placed on the original table. The following is the code that I am using. I keep getting an error:
Run-time error '3039'
Could not create index; Too many indexes already defined.
This occurs when I try to do the final table append. Any ideas?
Public Function ReIndex(table_name As String)
Dim db As Database
Dim tdf As TableDef
Dim tdf2 As TableDef
Dim idx As Index
Dim idx2 As Index
Dim strSrcTblName As String
Dim strTblName As String
Dim strTblCon As String
Stop
Set db = CurrentDb()
For Each tdf In db.TableDefs
If Mid(tdf.Name, 1, 4) <> "MSys" Then
If tdf.Indexes.Count > 0 Then
strSrcTblName = Mid$(tdf.SourceTableName, 5, Len(tdf.SourceTableName) - 4)
strTblName = tdf.Name
strTblCon = tdf.Connect
Set idx = tdf.Indexes(0)
Set tdf2 = db.CreateTableDef("Yo"
With tdf2
.Name = strTblName & "1"
.SourceTableName = strSrcTblName
.Connect = strTblCon
Set idx2 = tdf2.CreateIndex(idx.Name & "1"
With idx2
.Clustered = idx.Clustered
.Fields = idx.Fields
.IgnoreNulls = idx.IgnoreNulls
.Primary = idx.Primary
.Required = idx.Required
.Unique = idx.Unique
End With
.Indexes.Refresh
.Indexes.Append idx2
End With
db.TableDefs.Append tdf2
End If
End If
Next
End Function
Thanks
Graham Heath