table.FETCH_FIND Function

Syntax

Record_Number as N = Fetch_Find(A key)

Arguments

key

An expression used to select a record. The Matching_Expression and the table's or set's primary index key must have the same data type. Alpha Anywhere will automatically pad the Matching_Expression with trailing blanks if necessary so that the length of Matching_Expression matches the index key length. If the table's or set's primary index is record number order, then Matching_Expression is the record number that you want to find.

Description

Using the current index, find specified key value, return record number.

Discussion

The <TBL>.FETCH_FIND() method retrieves the first record in the table or set referenced by <TBL> with a primary index key equal to the Matching_Expression parameter. If <TBL>.FETCH_FIND()is successful, the found record is retrieved and its Record_Number is returned. If no exact match is found, a negative number corresponding to the record number of the closest matching record is returned.

Example 

This script is on a button on a form for a set in which the inv_item table is a child table. The script opens the product table. It then finds the record that matches product_id in the inv_item table, and assigns the value from the qty_stock field in product to the on_hand variable.

dim tbl_product as P
dim indx_1 as P
tbl_product = table.open("c:\data\product.dbf")
indx_1 = tbl_product.index_primary_put("id_index")
rec = tbl_product.fetch_find(inv_item->product_id)
if (rec > 0) then
    on_hand = tbl_product.qty_stock
else
    ui_msg_box("Record not found", "The closest match is record number " + abs(rec)")
end if
tbl_product.close()

This script opens a table and finds record 100.

dim tbl as P
dim indx_1 as P
tbl = table.open("d:\data\product.dbf")
'Select record number order
indx_1 = tbl.index_primary_put()
rec = tbl.fetch_find(100)

See Also