Public Function PaiMinChi(strTableName As String, strFieldName As String, strFieldName1 As String)
On Error GoTo PaiMinChi_Err:
Dim I As Long
Dim con As Object
Dim rs As Object
Dim stsql As String
Static same As Long
Set con = Application.CurrentProject.Connection
stsql = "SELECT * FROM "
stsql = stsql + strTableName
stsql = stsql + " ORDER BY " & strTableName & "." & strFieldName & " desc;"
Set rs = CreateObject("ADODB.Recordset")
rs.Open stsql, con, 3, 3
'如果表中没有记录则提示。
If (rs.EOF) Then
MsgBox "表中没有一条记录,已终止。", 48, "aiMinChi"
Else
While (Not (rs.EOF))
If rs(strFieldName) <> same Then
I = I + 1
same = rs(strFieldName)
End If
rs(strFieldName1) = I
rs.MoveNext
Wend
End If
'关闭打开的记录集
rs.Close
Set rs = Nothing
Set con = Nothing
PaiMinChi_Exit:
Exit Function
PaiMinChi_Err:
'提醒表不可以以独占方式打开(在MDB中)
If Err.Number = -2147467259 Then
MsgBox "该表已被以独占方式打开,请关闭此表", 48, "aiMinChi"
rs.Close
con.Close
Resume PaiMinChi_Exit
'其它错误
Else
MsgBox Err.Description & Err.Number, 48, "aiMinChi"
rs.Close
con.Close
Resume PaiMinChi_Exit
End If