Private Sub Form_Load()
Dim dbs As Database
Dim myrs As Recordset
Set dbs = OpenDatabase("C:\temp\CreateIndexLinked.mdb")
'These lines simply drop the index if it exists.
On Error Resume Next
dbs.Execute "Drop Index NewIndex on Table1"
dbs.Execute "Drop Index NewIndex on dbo_tbl_Indexed"
On Error GoTo 0
'This Execute tries to create a multiple-field index on the Access table.
'It will generate the 3277 Run-time error as expected.
' dbs.Execute "CREATE INDEX NewIndex ON Table1" _
' & "(fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8, fld9, fld10, fld11);"
'This Execute tries to create a multiple-field index with more than 10 fields on the attached SQL Server table.
'It will fail silently.
dbs.Execute "CREATE INDEX NewIndex ON dbo_tbl_Indexed " _
& "(fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8, fld9, fld10, fld11);"
'This Execute tries to create a multiple-field index with 10 fields on the attached SQL Server table.
'It will succeed.
' dbs.Execute "CREATE INDEX NewIndex ON dbo_tbl_Indexed " _
' & "(fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8, fld9, fld10);"
Set myrs = dbs.OpenRecordset("dbo_tbl_Indexed", dbOpenDynaset,
dbForwardOnly, dbOptimistic)
'The AddNew will fail, if the Execute that tries to create a multiple-field
'index with more than 10 fields on the attached SQL Server table is run.
myrs.AddNew
myrs(0) = 3
myrs(1) = 4
myrs(2) = 5
myrs(3) = 6
myrs(4) = 7
myrs(5) = 8
myrs(6) = 9
myrs(7) = 10
myrs(8) = 11
myrs(9) = 1
myrs(10) = 2
myrs.Update
dbs.Close
End Sub