Method
Sets the current key for a table handle.
Category
Keys
Syntax
Function SetCurrentKey(ByVal hTable As Long, ByVal Key As Variant)
As Boolean
hTable
The handle to the table.
Key
The desired key or an empty variant.
Example
CF1.OpenTable hTable, 18 ' customer table
longArray(0) = 1 ' field: "No."
longArray(1) = 3 ' field: "Search Name"
longArray(2) = 0
tmpVar = longArray
tmpVar2 = CF1.SetCurrentKey(hTable, tmpVar)
If VarType(tmpVar2) <> vbBoolean Then
logWr "SetCurrentKey failed. It didn't return a boolean"
End If
CF1.CloseTable hTable
Comments
SetCurrentKey assigns a specified key to a table handle. The key
becomes the current key and is used by FindRec, NextRec and other functions until another
key is selected. Use NextKey to
scan the list of keys for the table to find out which ones are
available. Only active keys will be retrieved.
The primary key of the table is the current key, until SetCurrentKey is called. When a secondary key is the current key, you can make the primary key the current key again by calling SetCurrentKey with Key set to an empty Variant.
If a new current key is successfully assigned to the table handle, TRUE is returned. If the requested key does not exist, two things can happen:
The function returns FALSE, and, unless the error has been allowed, an error message will be displayed if HideError is FALSE.
If this result has been allowed by the AllowKeyNotFound function, it will not be considered an error. The function, however, still returns FALSE; and you should test this return value in your code.
For more information about how errors are handled, see Error Handling.
For more information about keys, see the Application Designer’s Guide.