X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Change Value Before Or After A Record Is Saved, Access 2010    
post Apr 13 2017, 02:50 PM

Posts: 142
Joined: 31-August 07

Hi All
I have a button set up on a form that saves the record prior to previewing the report. Is it possible to modify a field in the record that is being saved? Do you do it before or after a save? I am not 100% sure that the code for DLookUp is correct for an VBA event. Thank you.

Private Sub Command108_Click()
On Error GoTo Button108_Click_Err

    DoCmd.RunCommand acCmdSaveRecord

    strContractorName = Nz(DLookUp("[Contractor]","[Project Info]","[Project ID] = " & [Forms]![Form Selector].[Combo49].[Column](0)),0)
    CurrentDb.Execute "INSERT INTO [Changes Log]([Contractor]) VALUES ('" & _
                              strContractorName & "')", dbFailOnError
    DoCmd.OpenReport "Test Report 2", acPreview, "Test Query 2", "[Forms]![Test Entry Form]![change id]=[change id]"

    Exit Sub

    MsgBox Error$
    Resume Button108_Click_Exit

End Sub
Go to the top of the page
post Apr 13 2017, 02:56 PM

UtterAccess VIP
Posts: 5,818
Joined: 31-August 06
From: North Carolina, USA

Do it before the save command. I am curious, though, why you are force saving the record. Another way you can do it is to what you want in the Form_BeforeUpdate event - then whatever code you put there is always executed before any changes are committed.
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    20th November 2018 - 11:18 AM