Mega Code Archive

 
Categories / VisualBasic Script / Access
 

Deleting a Field that is a Part of an Index with SQL command

Sub DeleteIdxField()      Dim conn As ADODB.Connection      Dim strTable As String      Dim strCol As String      Dim strIdx As String      On Error GoTo ErrorHandler      Set conn = CurrentProject.Connection      strTable = "myTable"      strCol = "myName"      strIdx = "multiIdx"      conn.Execute "ALTER TABLE " & strTable & " DROP CONSTRAINT " & strIdx & ";"      conn.Execute "ALTER TABLE " & strTable & " DROP COLUMN " & strCol & ";"  ExitHere:      conn.Close      Set conn = Nothing      Exit Sub  ErrorHandler:      Debug.Print Err.Number & ":" & Err.Description      Resume ExitHere  End Sub