Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching ODBC Views

Status
Not open for further replies.

datahound

MIS
Jun 15, 2000
6
CA
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) <> &quot;MSys&quot; 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(&quot;Yo&quot;)
With tdf2
.Name = strTblName & &quot;1&quot;
.SourceTableName = strSrcTblName
.Connect = strTblCon

Set idx2 = tdf2.CreateIndex(idx.Name & &quot;1&quot;)
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top