Sub CheckKeyPrimary()
On Error GoTo CreateKeyError
Dim cat As New ADOX.Catalog
Dim i As Byte
cat.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='c:\mas.mdb';"
With cat.Tables("品类")
If .Keys.Count < 1 Then MsgBox "没有主键": Exit Sub
For i = 0 To .Keys.Count - 1
If .Keys.Item(0).Type = adKeyPrimary Then MsgBox "有主键": Exit Sub
Next
MsgBox "没有主键"
End With
'Clean up
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Exit Sub
CreateKeyError:
Set cat = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub