我有一个显示 40 行的 Access 2007 表单。当我打开它时,我希望当前记录的行显示在显示的 40 行中的第 5 行位置。换句话说,当前行上面应该有 4 行,下面应该有 35 行。
MoveUpDown是我第一次这样做,但目前它仅在当前记录的行(由FindFirst移动到)最初显示在行位置 #1 到 #5 时才有效。如何找到当前行的显示位置,相对于显示的行,以及如何更改它?谢谢。
Private Sub OpenMyFormTo(sqlWhere As String)
Dim rs As DAO.Recordset, frm As Form
DoCmd.Openform "myForm", acNormal
Set frm = Forms("myForm").Form
Set rs = frm.RecordsetClone
If Not (rs.BOF And rs.EOF) Then
rs.MoveFirst
rs.FindFirst sqlWhere
frm.Bookmark = rs.Bookmark
MoveUpDown frm.Recordset, 5
End If
End Sub
Private Sub MoveUpDown(rs As DAO.Recordset, RowsToMove As Integer)
Dim RowsActuallyMoved As Integer, i As Integer
RowsActuallyMoved = 0
For i = 1 To RowsToMove
If Not rs.BOF Then
rs.MovePrevious
RowsActuallyMoved = RowsActuallyMoved + 1
End If
Next i
For i = 1 To RowsActuallyMoved
If Not rs.EOF Then rs.MoveNext
Next i
End Sub