AbsolutePosition Property Example

This example prompts the user for a record number. The example uses this number to move to a record in the Customer recordset in the Nwindex.mdb database, and then it copies the values for three specified fields to Sheet1.

To create the Nwindex.mdb database, run the Microsoft Excel example for the CreateDatabase method.

Set db = Workspaces(0).OpenDatabase(Application _
    .DefaultFilePath & "\NWINDEX.MDB")
Set rs = db.OpenRecordset("Customer", dbOpenSnapshot)
rs.MoveLast
lst = rs.RecordCount
Sheets("Sheet1").Activate
recordnumber = Application _
    .InputBox(Prompt:="Record number (1 - " & _
    lst & ") to copy to Sheet1", _
    Title:="Record to copy", Type:=1)
If recordnumber = False Or recordnumber > rs.RecordCount Then
    Exit Sub
End If
rs.AbsolutePosition = recordnumber - 1
With ActiveCell
    .Value = rs.Fields("COMPANY").Value
    .Offset(, 1).Value = rs.Fields("CITY").Value
    .Offset(, 2).Value = rs.Fields("REGION").Value
End With
rs.Close
db.Close