Results 1 to 2 of 2
  1. #1
    tim_tims33 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2011
    Posts
    62

    Running a Macro (on form's Close Event) only if new record has been added?

    Hi,



    I want to run a macro (on a form's Close Event), if only a new record has been added.

    It's for an Invoice system, and if a new invoice is to be added to frmInvoice, the following macro opens frmInvoice in Data Mode: Add.

    Click image for larger version. 

Name:	capture.JPG 
Views:	9 
Size:	13.9 KB 
ID:	31434


    Once a new record has been added to frmInvoice, I run another macro called mcrUpdateDiscountRate, that updates a table called tblInvoice.

    This macro is called/run on the CLOSE event of frmInvoice.


    The problem is, however, that if I want to simply view all my invoices, via frmInvoice, and then close the form...it still runs the macro mcrUpdateDiscountRate.

    How can I avoid running this macro, if I'm just viewing all the records in the form (I.e. not adding a new record)?

    thanks
    Attached Thumbnails Attached Thumbnails Capture2.JPG   Capture3.JPG  

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    It may not be a good idea. The user can start a new record and cancel it, but the new record is created anyway. (autonum ALWAYS creates a record)
    Instead of running it on CLOSE, you should check whether the user actually MADE the record.
    Maybe put a flag somewhere on the form (a hidden check box, or modular variable) .
    A SAVE button. (we know the record saves automatically, but the user may not and clicking is will fire the macro)
    the hidden checkbox, chkValid, is unchecked until the macro runs,
    the macro wont run until you validate the fields that MUST be entered to be a valid record.

    If the user closes the form, BEFORE chkValid is true, then cancel the close until the record is valid.
    if all reqd fields are valid, and user clicks 'save', and the macro runs, then it sets chkValid =true,
    and now the form can close.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-05-2015, 09:10 AM
  2. Replies: 1
    Last Post: 11-18-2014, 12:35 PM
  3. Replies: 2
    Last Post: 11-07-2014, 02:53 PM
  4. Replies: 7
    Last Post: 04-15-2014, 01:15 PM
  5. Replies: 4
    Last Post: 08-28-2013, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums