>
Part | Description |
recordset | The name of the Recordset object whose current record position is being moved. |
rows | A signed Long value specifying the number of rows the position will move. If rows is greater than 0, the position is moved forward (toward the end of the file). If rows is less than 0, the position is moved backward (toward the beginning of the file). |
start | A String value identifying a bookmark. If start is specified, the move begins relative to this bookmark. If start is not specified, Move begins from the current record. |
Sub MoveRelative (lngDistance As Long, strDirection As String, _ rstTarget As Recordset, varRelativeMark As Variant) Dim strHere As String strHere = rstTarget.Bookmark strDirection = UCase(strDirection) Select Case strDirection Case "FWD": lngDistance = Abs(lngDistance) Case "BACK": lngDistance = Abs(lngDistance) * -1 Case Else: MsgBox "Incorrect calling argument" End Select If UCase(varRelativeMark) = "HERE" Then
rstTarget.Move lngDistance ' Move current record position. Else ' Move relative to bookmark. rstTarget.Move lngDistance, varRelativeMark End If ' Move may not have been completed. If rstTarget.EOF Or rstTarget.BOF Then Beep End SubExample (Microsoft Access) The following example uses the Move method to move forward two rows in a Recordset object.
Sub MoveForward() Dim dbs As Database, rst As Recordset Dim strCriteria As String ' Return Database variable pointing to current database. Set dbs = CurrentDb ' Open Dynaset-Type Recordset object. Set rst = dbs.OpenRecordset("SELECT * FROM Orders " & _ "ORDER BY [ShipCountry];") rst.MoveFirst ' Check number of records in Recordset object. If rst.RecordCount > 2 Then ' Move forward two rows. rst.Move 2 Debug.Print rst!ShipCountry End If End SubExample (Microsoft Excel) This example prompts the user to select a record number. The example then copies the selected record from the Customer recordset in the NWINDEX.MDB database onto Sheet1.
Dim db As Database, rs As Recordset Set db = Workspaces(0).OpenDatabase(Application.Path & "\NWINDEX.MDB") Set rs = db.OpenRecordset("SELECT [CUSTMR_ID], [CONTACT], [REGION] " _ & "FROM Customer") Sheets("Sheet1").Activate aDistance = Application.InputBox("What record # you want to copy", Type:=2) If aDistance = False Then ' user cancelled InputBox Exit Sub End If rs.MoveFirst rs.Move aDistance For i = 0 To 2 ActiveCell.Offset(, i).Value = rs.Fields(i).Value Next rs.Close db.Close