Method
Inserts a record in a table.
Category
Records
Syntax
Function InsertRec(ByVal hTable As Long, ByVal hRec As Long) As
Boolean
hTable
The handle to the table.
hRec
The handle to the record that is to be inserted. hRec itself does
not change.
Example
'Case "InsertRec"
'Inserts a row in table 18 (customer)
CF1.OpenTable hTable, 18
'First Row
hRecord = CF1.AllocRec(hTable)
tmpVar = "__DATA__"
CF1.BWT
CF1.InitRec hTable, hRecord
CF1.AssignField hTable, hRecord, 1, tmpVar
tmpVar2 = CF1.InsertRec(hTable, hRecord)
If VarType(tmpVar2) <> vbBoolean Then
logWr "InsertRec failed. It didn't return a Boolean"
End If
CF1.EWT
CF1.FreeRec hRecord
CF1.CloseTable hTable
logWr "Record inserted"
Comments
InsertRec inserts a record into an open table. Use InitRec to initialize the record before
assigning values to the fields. The current key and any filters
that have been placed on the table handle do not effect this
operation.
A record is uniquely identified by the values of the fields in the primary key. The C/SIDE database manager inspects the primary keys in the table before inserting the new record.
If the record is successfully inserted, the function returns TRUE. If a record with the same value in the primary key already exists in the table, the insertion will fail and 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 AllowRecordExists 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.