Public Function Keyname(tbname As String, ktype As Long) As String
'功能:获取数据表键列字段名称
'参数:tbname---表名;ktype---键类型(1为主键,2为外键,3为{wy}键)
Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim i As Long, j As Long
Set cnn = CurrentProject.Connection
Set cat.ActiveConnection = cnn
Set tbl = cat.Tables(tbname)
For i = 0 To tbl.Keys.Count - 1
If tbl.Keys(i).Type = ktype Then
For j = 0 To tbl.Keys(i).Columns.Count - 1
Keyname = Keyname & tbl.Keys(i).Columns(j).Name & ";"
Next
End If
Next
End Function