Access 2007 Using the After Insert event to trigger operations using information from that inserted record

Posted on 2008-11-06
Last Modified: 2010-08-05
Hello again

I know this answer is probably an obvious one but not to me at the moment so...

I have a sub-form which allows the user to add new entries to a table. When a new record is added I want to carry out various automatic procedures based on the values of this new record.

This processing can only occur once ALL the values have been added to the new record. So I thought the AfterInsert event would be the one to use.

The trouble is for the After Insert event to be triggered the user has moved off the inserted record so that it is no longer current and I can no longer access the appropriate data.

How do I (or is it possible to) access the data in the inserted record once all the req fields have been completed.

It is a multi-user DB so others may me adding new records to this table also.

Many thanks
Question by:stillers1994
    LVL 46

    Expert Comment

    Hi stillers1994,

    You can call a function after each field has been updated & only if it sees that all the fields have been entered will it call your other procedures

    Good Luck!

    LVL 75

    Accepted Solution

    Try using the Form AfterUpdate event instead, like such - add these code snippets:

    Option Compare Database
    Option Explicit
        Dim fIsNewRecord As Boolean

    Private Sub Form_BeforeUpdate(Cancel As Integer)
        If Me.NewRecord = True Then fIsNewRecord = True
    End Sub

    Private Sub Form_AfterupDate()
       If fIsNewRecord  = True Then
          ' Do the automatic stuff
      End If
      fIsNewRecord = False
    End Sub

    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    "The trouble is for the After Insert event to be triggered the user has moved off the inserted record"

    Actually, that is not the case.  The focus remains on the record just added - UNLESS - you simply use the Navigation buttons to 'save' the record by moving to a new record.  If you have a Save button which saves the record, then focus will stay on the new record just added.


    Author Closing Comment

    Many thanks.  I did use this idea but I also had to use more public variables in the BeforeUpdate sub to store the various data values from the new record as I didn't want to add yet another button on by form (ie Save) as the user would  position off the new record before the.
    required task would trigger. Seem to work just wondered whether I was missing something obvious.
    Thanks again

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now