Deletes a record from a table.



Function DeleteRec(ByVal hTable As Long, ByVal hRec As Long) As Boolean

The handle to the table.

The handle to the record that is to be deleted. hRec itself does not change.



' 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)



  ' hRec now points to the record we want to delete


  tmpVar = CF1.DeleteRec(hTable, hRecord)

  If VarType(tmpVar) <> vbBoolean Then

  logWr "DeleteRec failed. It didn't return a Boolean"

  End If


  CF1.FreeRec hRecord

  CF1.CloseTable hTable

  logWr "Record deleted"


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:

For more information about table locking, see the Application Designer’s Guide.

For more information about how errors are handled, see Error Handling.

© 2009 Microsoft Corporation. All rights reserved.