Steps through a specified number of records to retrieve a record.



Function NextRec(ByVal hTable As Long, ByVal hRec As Long, ByVal Step As Short) As Short

The handle to the table.

As input: The record from which the search will begin.

As output: The record that is found. Any FlowFields associated with the record are set to zero; use CalcFields to update these fields.

Number of steps. If Step=0, the function has no effect. To move backwards through the table, use a negative number.



 ' Case "FindRec", AllocRec and NextRec

 ' Open Table 15 (G/Ledger)

  CF1.OpenTable hTable, 15

  hRecord = CF1.AllocRec(hTable)


  ' get last record

  tmpVar = CF1.FindRec(hTable, hRecord, "+")

  If VarType(tmpVar) = vbBoolean Then

  logWr "FindRec OK"


  logWr "FindRec failed. It didn't return a boolean"

  End If

  tmpLastRecord = CF1.GetFieldData(hTable, hRecord, 1)


  ' loop through records

  CF1.FindRec hTable, hRecord, "-"

  tmpLong2 = 1 'used to count no of records

  tmpLong = CF1.GetFieldData(hTable, hRecord, 1)

  Do While tmpLong <> tmpLastRecord

  tmpVar = CF1.NextRec(hTable, hRecord, 1)

  If VarType(tmpVar) <> vbInteger Then

  logWr "NextRec failed. It didn't return an Integer"

  End If

  tmpLong = CF1.GetFieldData(hTable, hRecord, 1)

  tmpLong2 = tmpLong2 + 1


  logWr "Stepped through " & Trim$(Str$(tmpLong2)) & " records. Data from the last one: " + Str$(tmpLastRecord)


  CF1.FreeRec hRecord


NextRec locates a record positioned a given number of steps before or after the record referenced by hRec. Movement through the table is governed by the filters and the current key associated with the table handle. All fields in hRec which will be compared to the current key must contain relevant values before this function is called.

The function returns the number of records traversed which meet the criteria set by any filters, given the current key. This value can be closer to zero than Step, depending upon the number of records in the table. If the table is empty, zero is returned and hRec remains unchanged.

© 2009 Microsoft Corporation. All rights reserved.