Adding a Unique Index Based on Two Fields to an Existing Table
Sub AddMulti_UniqueIndex()
Dim conn As ADODB.Connection
Dim strTable As String
Dim strCol As String
On Error GoTo ErrorHandler
Set conn = CurrentProject.Connection
strTable = "myTable"
strCol = "Id, Name"
conn.Execute "ALTER TABLE " & strTable & " ADD CONSTRAINT multiIdx UNIQUE(" & strCol & ");"
ExitHere:
conn.Close
Set conn = Nothing
Exit Sub
ErrorHandler:
Debug.Print Err.Number & ":" & Err.Description
Resume ExitHere
End Sub
Related examples in the same category