BeforeDelete Event

Microsoft Office Web Components Object Model

BeforeDelete Event

       

Occurs before a record is deleted. Use this event if you want to apply a set of conditions before a record is deleted.

Private Sub Object_BeforeDelete(ByVal DSCEventInfo As DSCEventInfo)

Object   A DataSourceControl object.

DSCEventInfo   The DSCEventInfo object that contains information about the event.

Remarks

Set the ReturnValue property of the DSCEventInfo object to False to cancel the deletion of a record. When you cancel the deletion of a record, the AfterDelete event still fires.

Use the DataPage and Section properties of the DSCEventInfo object to determine the data access page, section, and recordset that was updated.

Use the DisplayAlert property to determine whether or not the user is prompted when this event is called.

Example

This example cancels the deletion of a record if the "Discontinued" field is set the No.

Sub MSODSC_BeforeDelete(DSCEventInfo)

   Dim txtDiscontinued

   ' Set a variable to the text box that contains the value
   ' of the Discontinued field for the record that is to be deleted.
   Set txtDiscontinued = DSCEventInfo.Section.HTMLContainer _
                        .Children("Discontinued")

   ' Check the value of the control.
   If txtDiscontinued.Value = "No" Then

      ' Display a message to the user.
      Msgbox "Do not delete products that have not " & _
             "been discontinued."

      Cancel the deletion of the record.
      DSCEventInfo.ReturnValue = False
   End If

End Sub