Office中国论坛/Access中国论坛

标题: [求助]怎样获取指定表中所有的主键名? [打印本页]

作者: HG    时间: 2004-4-16 17:59
标题: [求助]怎样获取指定表中所有的主键名?
Sub testKey()
On Error GoTo err_this
    Dim adoxcat As New ADOX.Catalog
    Dim adoxtbl As New ADOX.Table
    Dim adoxkey As New ADOX.Key
    Dim intKeys As Integer
    Dim intKey As Integer
   
    strTblName = "L_CustVirtualStoreDetail"
    adoxcat.ActiveConnection = CurrentProject.Connection
   
    Set adoxtbl = adoxcat.Tables(strTblName)
    Debug.Print adoxcat.Tables(strTblName).name
'    Set adoxkey = adoxtbl.Keys
   

'    For Each adoxkey In adoxtbl.Keys
        intKeys = adoxtbl.Keys.Count - 1
        For intKey = 0 To intKeys
            Debug.Print adoxtbl.Keys.Item(intKey).name
        Next intKey
'        Debug.Print adoxkey.Columns
        Debug.Print adoxkey.name, adoxkey.Type
        
'    Next
   
    Set adoxkey = Nothing
    Set adoxtbl = Nothing
    Set adoxcat = Nothing
exit_sub:
    Exit Sub
err_this:
    MsgBox Err.Description, vbOKOnly + vbCritical, Err.Number
    Resume exit_sub
End Sub
但是我现在得到的并不是Key所在列的名字?问怎么得到?谢!




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3