Home   Fees/Services   Access Templates   Tutorials  Tutorial Downloads   Articles   Search   Contact  Privacy  Links

VBA Before Update

Access Event Tutorials:
Before Insert Event
After Insert Event
After Update Event
Before Update Event
Change Event
Close Event
Current Event
Double Click Event
Error Event
Exit Event
VBA Timer Event
Undo Event

Table-Level Events

BeforeUpdate Event Access Example

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.

Microsoft Access is a fully capable database and it's primary limitations is the number of concurrent users it will support. Generally, we recommend a limit of 10 to 15 users.

We create databases large and small. Some of our databases help run entire small businesses. We also handle unique businesses such as flyrod manufacturing, cheese making, marina management, and cable tv inventory.

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"
        Cancel=True      ' caused the changes to not be saved
    End If
End Sub

Here is another beforeupdate example from our downloadable Access inventory database demo:

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
End If
End Sub

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 problem.

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 place.

To try this beforeupdate example out on your computer you can go to our download center and download the single-user inventory demo database.

Form Triggers
Table Triggers
Form Flags
Table Triggers
Record Flags
Record Events

A Blue Claw Database Design Template:

Loan Process Management Access Database

A Blue Claw Database Design Article:

Microsoft Access On The Internet

Microsoft Office:
MS Access 2003
Access 2007
Access 2010
Access 2013
Access 2016

Contact Information

Copyright 2000-2017 Blue Claw Database Design