Office中国论坛/Access中国论坛

标题: 求获取窗体中记录总数和当前记录为第几条记录的函数!(解决) [打印本页]

作者: sxgaobo    时间: 2010-6-21 07:43
标题: 求获取窗体中记录总数和当前记录为第几条记录的函数!(解决)
本帖最后由 sxgaobo 于 2010-6-22 13:39 编辑

同题
作者: gaofei186    时间: 2010-6-21 08:41
我记得access2007中就有很直接的
作者: sxgaobo    时间: 2010-6-21 10:41
RecordsetClone.RecordCount,可以获取窗体中总记录数,如何获取当前记录为第几条?
作者: sxgaobo    时间: 2010-6-21 17:55
帮忙啊!!!
作者: fnsmydyang    时间: 2010-6-21 21:18
帮忙了,坛上的
NO. 1:
=RecordNumber("第",me)'me指当前窗体

Function RecordNumber(pstrPreFix As String, pfrm As Form) As String
On Error GoTo RecordNumber_Err
Dim rst
Dim lngNumRecords As Long
Dim lngCurrentRecord As Long
Dim strTmp As String

Set rst = pfrm.RecordsetClone
rst.MoveLast
rst.Bookmark = pfrm.Bookmark
lngNumRecords = rst.RecordCount
lngCurrentRecord = rst.AbsolutePosition + 1
strTmp = pstrPreFix & " " & lngCurrentRecord & " 页," & " 共 " & lngNumRecords & " " & "页"
RecordNumber_Exit:
On Error Resume Next
RecordNumber = strTmp
rst.Close
Set rst = Nothing
Exit Function
RecordNumber_Err:
Select Case Err
Case 3021
strTmp = "New Record"
Resume RecordNumber_Exit
Case Else
strTmp = "#" & Error
Resume RecordNumber_Exit
End Select
End Function

NO. 2
Function RecordNum(frmData As Form) As String
On Error Resume Next
    frmData.RecordsetClone.MoveLast
    DoEvents
    If frmData.NewRecord = True Then
        RecordNum = "新记录" & "/共" & frmData.RecordsetClone.RecordCount & "条"
    Else
        RecordNum = "记录" & frmData.CurrentRecord & "/共" & frmData.RecordsetClone.RecordCount & "条"
    End If
End Function
文章来自:Access之家(http://www.AccessHome.cn/) 详细出处请参考:http://accesshome.5d6d.com/viewt ... Borderby%3Ddateline
作者: sxgaobo    时间: 2010-6-22 13:39
谢谢 fnsmydyang !!!
就是要它 CurrentRecord




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