Dim dbsNorthwind As Database
   Dim tdfEmployees As TableDef
   Dim idxLoop As Index   Set dbsNorthwind = OpenDatabase("Northwind.mdb")
   Set tdfEmployees = dbsNorthwind!Employees   With tdfEmployees      ' Enumerate Indexes collection of Employees 
      ' table.
      For Each idxLoop In .Indexes
 If idxLoop.Primary Then Debug.Print "  Primary Key:";
         Debug.Print "  " & idxLoop.Name
      Next idxLoop
   End With   dbsNorthwind.Close

解决方案 »

  1.   

    你可以试一试sql里面的isprimarykey
      

  2.   

    "sql里面的isprimarykey", 有吗,能否具体点?
      

  3.   

    在asp或者其他客户端程序中执行sp_columns tablename存储过程,然后会返回一个结果集。把data_type为4的取出来就是你的关键子。你在查询分析器中一试就知道了。
      

  4.   

    在楼上给了你DAO方法。
    下面是ADO方法:(这是微软网站上的例子)
    Private Function FindPrimaryKey( _
     tbl As ADOX.Table) As Variant
        
        ' Given a particular table, find the primary
        ' key name, if it exists.
       
        ' Returns the name of the primary key's index, if
        ' it exists, or Null if there wasn't a primary key.
       
        Dim idx As ADOX.Index
       
        For Each idx In tbl.Indexes
            If idx.PrimaryKey Then
                FindPrimaryKey = idx.Name
                Exit Function
            End If
        Next idx
        FindPrimaryKey = Null
    End Function