Inserts a record in a table.
Function InsertRec(ByVal hTable As Long, ByVal hRec As Long) As Boolean
The handle to the table.
The handle to the record that is to be inserted. hRec itself does not change.
'Inserts a row in table 18 (customer)
CF1.OpenTable hTable, 18
hRecord = CF1.AllocRec(hTable)
tmpVar = "__DATA__"
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"
logWr "Record inserted"
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.