Remove index

a7n9

Well-known Member
Joined
Sep 15, 2004
Messages
696
Hello all,

I'd like to remove every index of a table. I didn't find any property, which can do this. All I could come up with was the indexed field names. Can anyone help me with this.

Code:
'remove indexes from a table
Public Sub remove_index()
Dim catcurr As New ADOX.Catalog
'Dim tbl As ADOX.Table
Dim idx As ADOX.Index
Set catcurr.ActiveConnection = CurrentProject.Connection
'tbl.Name = "STU200501_0110052"
With catcurr.Tables("data")
For Each idx In .Indexes
'Debug.Print idx.Name
Debug.Print idx.Properties.Count
'idx
Next
End With
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
The following will remove one index from a table:
Code:
Public Sub remove_index()
Dim catcurr As New ADOX.Catalog
Dim idx As ADOX.Index
    
    Set catcurr.ActiveConnection = CurrentProject.Connection

    With catcurr.Tables("data")
        For Each idx In .Indexes
    
            .Indexes.Delete idx.Name
        
        Next
    End With
End Sub
I can't see why it won't delete >1. I'll have a play about with it.

Try this
Code:
Public Sub remove_index()
Dim catcurr As New ADOX.Catalog
Dim idx As ADOX.Index
    
    Set catcurr.ActiveConnection = CurrentProject.Connection

    With catcurr.Tables("data")
    
        While .Indexes.Count <> 0
        
            Set idx = .Indexes(0)
            
            .Indexes.Delete idx.Name
            
        Wend
        
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,864
Messages
6,162,497
Members
451,770
Latest member
tsalaki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top