Resources » Code Snippets » MS Access

MS Access : Remove Index From MDB programmatically


Posted Date: 25-Jun-2009  Last Updated:   Category: MS Access    
Author: Member Level: Gold    Points: 10



The following VBA code is used to remove the index from MS Access table programmatically.

We need to assign the database to Database type variable.

Then get the table value into tabledef collection. Then using delete command we can remove the indexes.



Sub RemoveIndexFromMSAccessDB()

'Declaration of Variables
Dim indexName As String
Dim AccessDb As Database
Dim Td As TableDef

'Error Handler
On Error Go to ErrHandler

'Assign the database
Set AccessDb = OpenDatabase("C:\Test.MDB")


If Err.Number <> 0 Then

'failed to open access database

MsgBox "Error " & Err.Description & "Err No " & Err

Exit Sub
End If

'Assign Index

indexName = "MyIndex"

'get table

Set Td = AccessDb.TableDefs("MyTable1")

If Err.Number <> 0 Then

'failed to get table
GoTo ErrHandler

End If

With Td

On Error Resume Next
.Indexes.Delete IndexName

End With



ErrHandler:

MsgBox "Error " & Err.Description & "Err No " & Err

End Sub



Did you like this resource? Share it with your friends and show your love!

Responses to "MS Access : Remove Index From MDB programmatically"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Rameshkumar
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India