Hi Gorden,
While looking for something else, I found
a routine in NEAT CD db that I adapted
into 2 functions that would have helped us
find what indexes you had on your table and
what their name(s) were so you could drop them.
Function GetPrimaryKeyName(pstrTableName As String) As String
'adapted from NEAT CD
' Gets the name of the primary key index of a table
' If none found, returns ""
On Error GoTo Err_GetPrimaryKeyName
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim indx As DAO.Index
Dim i As Integer
Set db = CurrentDb
Set tdf = db.TableDefs(pstrTableName)
GetPrimaryKeyName = ""
For i = 0 To tdf.Indexes.Count - 1
Set indx = tdf.Indexes(i)
If indx.Primary Then
GetPrimaryKeyName = indx.Name
Exit For
End If
Next i
db.Close
Exit_GetPrimaryKeyName:
Set tdf = Nothing
Set db = Nothing
Exit Function
Err_GetPrimaryKeyName:
If Err = 3265 Then
MsgBox "The table " & pstrTableName & " does not exist."
Resume Exit_GetPrimaryKeyName
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume Exit_GetPrimaryKeyName
End If
End Function
Function GetIndexes(pstrTableName As String) As Boolean
'adapted from NEAT CD
' Prints indexes in Immediate Window
On Error GoTo Err_GetIndexes
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim indx As DAO.Index
Dim i As Integer
Set db = CurrentDb
Set tdf = db.TableDefs(pstrTableName)
Debug.Print "TableName: " & pstrTableName
Debug.Print "Index Count: " & tdf.Indexes.Count
For i = 0 To tdf.Indexes.Count - 1
Set indx = tdf.Indexes(i)
Debug.Print vbCrLf & "Index Name: " & indx.Name
Debug.Print " Primary: " & indx.Primary
Debug.Print " Foreign: " & indx.Foreign
Debug.Print " Clustered: " & indx.Clustered
Debug.Print " Fields: " & indx.Fields
Debug.Print " Required: " & indx.Required
Debug.Print " Unique: " & indx.Unique
Debug.Print " Ignore Nulls: " & indx.IgnoreNulls
Next i
db.Close
GetIndexes = True
Exit_GetIndexes:
Set tdf = Nothing
Set db = Nothing
Exit Function
Err_GetIndexes:
GetIndexes = False
If Err = 3265 Then
MsgBox "The table " & pstrTableName & " does not exist."
Resume Exit_GetIndexes
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume Exit_GetIndexes
End If
End Function
Sigh...I guess I will know next time.
Gary Walter