Recordset2.Move 方法 (DAO)
适用于:Access 2013、Office 2013
移动 Recordset 对象中当前记录的位置。
语法
表达式 。移动 (行, StartBookmark)
表达 一个代表 Recordset2 对象的变量。
参数
名称 |
必需/可选 |
数据类型 |
说明 |
---|---|---|---|
Rows |
必需 |
Long |
位置移动的行数。 如果行数大于 0,则向前移动位置(朝着文件末尾移动)。 如果行数小于 0,则向后移动位置(朝着文件开头移动)。 |
StartBookmark |
可选 |
Variant |
一个用于标识书签的值。 如果指定 StartBookmark,则会相对此书签开始移动。 否则,从当前记录开始移动。 |
说明
如果使用 Move 将当前记录指针定位在第一条记录之前,当前记录指针将移到文件的开头。 如果 Recordset 不包含记录,并且它的 BOF 属性为 True,则使用此方法后移会导致错误。
如果使用 Move 将当前记录指针定位在最后一条记录之后,当前记录指针将移到文件的末尾。 如果 Recordset 不包含记录,并且它的 EOF 属性为 True,则使用此方法前移会导致错误。
如果 BOF 和 EOF 属性中的一个为 True,并且您试图在不使用有效书签的情况下使用 Move 方法,将会发生运行时错误。
注意
示例
以下示例使用 Move 方法基于用户输入来定位记录指针。
Sub MoveX()
Dim dbsNorthwind As Database
Dim rstSuppliers As Recordset2
Dim varBookmark As Variant
Dim strCommand As String
Dim lngMove As Long
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstSuppliers = _
dbsNorthwind.OpenRecordset("SELECT CompanyName, " & _
"City, Country FROM Suppliers ORDER BY CompanyName", _
dbOpenDynaset)
With rstSuppliers
' Populate recordset.
.MoveLast
.MoveFirst
Do While True
' Display information about current record and ask
' how many records to move.
strCommand = InputBox( _
"Record " & (.AbsolutePosition + 1) & " of " & _
.RecordCount & vbCr & "Company: " & _
!CompanyName & vbCr & "Location: " & !City & _
", " & !Country & vbCr & vbCr & _
"Enter number of records to Move " & _
"(positive or negative).")
If strCommand = "" Then Exit Do
' Store bookmark in case the Move doesn't work.
varBookmark = .Bookmark
' Move method requires parameter of data type Long.
lngMove = CLng(strCommand)
.Move lngMove
' Trap for BOF or EOF.
If .BOF Then
MsgBox "Too far backward! " & _
"Returning to current record."
.Bookmark = varBookmark
End If
If .EOF Then
MsgBox "Too far forward! " & _
"Returning to current record."
.Bookmark = varBookmark
End If
Loop
.Close
End With
dbsNorthwind.Close
End Sub