The beforeupdate form event give you the ability to review the data entered by the user just before it is stored in the database.
BeforeUpdate event code is most often associated with data validation through visual basic script programming. BeforeUpdate event is activated in VBA before changed data in a
record is saved to the record source.
Are you just starting out on your quest for a small business database? Need some advice or someone to bounce ideas off of? We are happy to chat with you to discuss options to your situation.
Are you looking for an MS Access template database? We have many for sale in our Access Template and Examples Software section.
BeforeUpdate Event Example:
Visual Basic BeforeUpdate event is most often used to validate form
fields - here's a database programming example:
Private Sub Due_Date_BeforeUpdate(Cancel As Integer)
If Me.Due_Date<Me.Start_Date then
Msgbox "The Due Date must not come
before the Start Date"
' caused the changes to not be saved
Here is another beforeupdate example from our downloadable Access inventory
Private Sub Barcode_Combo_BeforeUpdate(Cancel As Integer)
Dim icount As Long
'check to see if this is a duplicate value before updating
icount = Nz(DLookup("barcode", "m_inv_out_items", "barcode=" & Me.BarCode), 0)
If icount <> 0 Then
' this item has already been selected
MsgBox "You have already selected this item."
Cancel = True
The purpose of the beforeupdate code above is to prevent the nasty Access
error message that pops up when a user enters an item in the list that has
already been entered. The code checks to see if the item has already been
selected. If it has then a message pops up telling the user about the
Finally the code clears out the value that has been selected.
With Access 2010 comes new table-level events. There is a
before change event which can be used as you use the before update event in
forms. The before change table event gives you the ability to write macro
code to perform data manipulation and validation before a data change takes
To try this beforeupdate example out on your computer you can go to our
download center and download the
single-user inventory demo database.