Results 1 to 3 of 3
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Button to trigger before event code after saving current record

    Hi.

    i am adding new record to form but primary key is updated only when i am going to next record (or saving current one).

    something like here:

    https://www.experts-exchange.com/que...xt-record.html

    I am trying to avoid this creating button with code:


    Code:
    If Me.NewRecord Then
    
    
        DoCmd.RunCommand acCmdSaveRecord
        MsgBox "Record added"
        Me.Recalc
    
    
    Else
    
    
      MsgBox "ups"
    
    
    End If
    but code before saving record is going to beforeupdate event:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    
    
    
       If Me.NewRecord Then
           Call AuditChanges("TopoToJunction_ID", "NEW")
       Else
           Call AuditChanges("TopoToJunction_ID", "EDIT")
      End If
    
    
    End Sub
    Within this event i am calling function to track changes within audti table.
    Problem is that here i am using field TopoToJunction_ID which is not updated until current, inserted record is saved...



    Can you help?
    Best,
    Jacek

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    You MUST save the record before you can do anything, THEN you can run an update.
    this would happen in the AFTERUPDATE event of the record.

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    thank you ranman256,

    your solution is working !

    Best,
    Jacek

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

Similar Threads

  1. Replies: 4
    Last Post: 10-29-2014, 03:49 PM
  2. Event trigger at loading each record
    By xcheshirecat in forum Forms
    Replies: 5
    Last Post: 06-12-2014, 10:11 AM
  3. how to trigger a button event at same form
    By newaccess in forum Forms
    Replies: 10
    Last Post: 03-01-2013, 10:02 AM
  4. Trigger event with button click
    By AMAS in forum Forms
    Replies: 8
    Last Post: 06-07-2012, 09:42 AM
  5. event to trigger after new record
    By richlyn in forum Access
    Replies: 1
    Last Post: 03-02-2012, 10:26 AM

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