|
鱼儿游游 发表于 2011-12-7 22:35
斑竹,我试了,发现有以下问题,能不能再改进一下。
要是当前ACCESS数据库,可以取回自动编号的字段。
要 ... - Public Function AutoNumIs(ByVal tblName As String) As String
- Dim rs As New ADODB.Recordset
- Dim cnn As New ADODB.Connection
- Dim intCount As Integer
- Dim strName As String
- On Error GoTo AutoNumIs_Error
- 'Set cnn = CurrentProject.Connection
- cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
- CurrentProject.Path & "/ABC.mdb;Jet OLEDB:database password="
- cnn.Open
- rs.Open tblName, cnn, adOpenKeyset, adLockReadOnly
- For intCount = 0 To rs.Fields.Count - 1
- If rs.Fields(intCount).Properties("isautoincrement") Then
- strName = rs.Fields(intCount).Name
- Exit For
- End If
- Next
- If Len(strName) <> 0 Then
- AutoNumIs = strName
- Else
- AutoNumIs = "Not Find"
- End If
- rs.Close
- Set rs = Nothing
- On Error GoTo 0
- Exit Function
- AutoNumIs_Error:
- MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
- End Function
复制代码 abc是你的库名,保存在一样的目录里 |
|