Method
Deletes a record from a table.
Category
Records
Syntax
Function DeleteRec(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 deleted. hRec itself does
not change.
Example
' Case "DeleteRec"
'Deletes the record in table 18
'
CF1.OpenTable hTable, 18
hRecord = CF1.AllocRec(hTable)
CF1.FindRec hTable, hRecord, "-"
tmpVar2 = CF1.GetFieldData(hTable, hRecord, 1)
Do While tmpVar2 <> tmpVar
If (Not CF1.FindRec(hTable, hRecord, ">")) Then
Exit Sub
End If
tmpVar2 = CF1.GetFieldData(hTable, hRecord, 1)
Loop
' hRec now points to the record we want to delete
CF1.BWT
tmpVar = CF1.DeleteRec(hTable, hRecord)
If VarType(tmpVar) <> vbBoolean Then
logWr "DeleteRec failed. It didn't return a Boolean"
End If
CF1.EWT
CF1.FreeRec hRecord
CF1.CloseTable hTable
logWr "Record deleted"
Comments
DeleteRec deletes a record from an open table. The current key and
any filters bound to the table handle have no effect on this
operation. The record to be deleted is identified only by the
values in its primary key.
In a multiuser environment, another application can delete the record from the table in the interval between your reading the record and your attempt to delete it. The C/SIDE database system automatically detects such an event, causing DeleteRec to fail.
To prevent this from happening, use LockTable to lock the table before reading the record. Remember, however, that the table will be locked for the entire time that elapses between reading and deleting the record, and that other users will therefore be unable to access it.
If the record is successfully deleted, the function returns TRUE. If the record is not found in the table, 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 AllowRecordNotFound 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 table locking, see the Application Designer’s Guide.
For more information about how errors are handled, see Error Handling.