Share via


BeforeUpdate Event

Occurs when data is changed, but before the recordset is updated. Use this event to validate data before it is committed to the database.

Private Sub Object_BeforeUpdate(ByVal DSCEventInfo As DSCEventInfo)

Object    A DataSourceControl object.

DSCEventInfo    The DSCEventInfo object that contains information about the event.

Remarks

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

Set the ReturnValue property of the DSCEventInfo object to False to cancel the update.

Example

This example cancels the updating of the recordset when the user enters a value greater than 0 for the UnitsOnOrder field when the UnitsInStock field is greater than 100.

Sub MSODSC_BeforeUpdate(DSCEventInfo)

   Dim txtUnitsOnOrder
   Dim txtUnitsInStock

   ' Set a variable to the text box that contains the value
   ' for the UnitsOnOrder field.
   Set txtUnitsOnOrder = DSCEventInfo.Section.HTMLContainer _
                         .Children("UnitsOnOrder")

   ' Set a variable to the text box that contains the value
   ' for the UnitsInStock field.
   Set txtUnitsInStock = DSCEventInfo.Section.HTMLContainer _
                         .Children("UnitsInStock")

   ' Check the value of the UnitsOnOrder Field.
   If CLng(txtUnitsOnOrder.Value) > 0 then

      ' Check the value of the UnitsInStock Field.
      If CLng(txtUnitsInStock.Value) > 100 then

         ' Display a message to the user.
         MsgBox "Don't reorder the part until fewer than 100 are in stock."

         ' Cancel the update.
         DSCEventInfo.ReturnValue = False

      End If
   End If

End Sub

Applies to | DataSourceControl Object

See Also | AfterUpdate Event | DataPage Property | DSCEventInfo Object | ReturnValue Property | Section Property