BeforeInsert Event

Microsoft Office Web Components Visual Basic

Private Sub Object_BeforeInsert(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 insertion of a new record.

You can use the DataPage property of the DSCEventInfo object to get more information about the data access page.

Example

This example uses the BeforeInsert event to prevent the user from adding another record to the recordset once it reaches 75 records.

Sub MSODSC_BeforeInsert(DSCEventInfo)
   Dim rstCurrentData

   ' Set a variable to the recordset.
   Set rstCurrentData = DSCEventInfo.DataPage.Recordset

   ' Check to see if the recordset has reached its limit.
   If rstCurrentData.RecordCount >= 75 then

      ' Display a message to the user.
      MsgBox "Cannot add any more records."

      ' Cancel the insertion of the record.
      DSCEventInfo.ReturnValue = False
   End If
End Sub