Here's somethng I've whipped up in my test database.
I have a table named "tbl_events "
I made an empty copy of "tbl_events " and renamed it "tbl_audit" , change the [eve_id] from an autonumber to a number
Added two new fields [Audit_ID] as autonumber and primary key and [Audit_date] as a date field... should have added a third for the currently logged in user; however, that should be easy for you to do...
I have a form that is based on a query against the tbl_events with a control named "EVE_ID" and in that form the following code... :
Debugged and ran on 10 records in the test db w/o problems.
Now you have a copy of the old record with date changed... the rest is up to you :)
-z
I have a table named "tbl_events "
I made an empty copy of "tbl_events " and renamed it "tbl_audit" , change the [eve_id] from an autonumber to a number
Added two new fields [Audit_ID] as autonumber and primary key and [Audit_date] as a date field... should have added a third for the currently logged in user; however, that should be easy for you to do...
I have a form that is based on a query against the tbl_events with a control named "EVE_ID" and in that form the following code... :
Code:
Option Compare Database Option Explicit ' Private Sub Form_BeforeUpdate(Cancel As Integer) 'declare Dim zdb As dao.Database Dim zrs As dao.Recordset Dim zssql As String Dim zieid As Integer Dim zddate As Date ' 'setup Set zdb = CurrentDb Set zrs = zdb.OpenRecordset("tbl_audit", dbOpenDynaset) ' 'set error trap On Error GoTo z_bad_error_nonono ' 'set var zddate = Format(Date, "mm/dd/yyyy") zieid = Me![Eve_ID] ' 'build sql zssql = _ "INSERT INTO tbl_audit ( Eve_ID, Eve_Inv_ID, Eve_Sta_ID, Eve_Date, Eve_memo, Eve_Inls, Eve_WinUserID ) " & _ "SELECT tbl_events.[Eve_ID], tbl_events.[Eve_Inv_ID], tbl_events.[Eve_Sta_ID], tbl_events.[Eve_Date], tbl_events.[Eve_memo], tbl_events.[Eve_Inls], tbl_events.[Eve_WinUserID] " & _ "FROM tbl_events " & _ "WHERE (((tbl_events.[Eve_ID])= " & zieid & "));" ' 'copy the current record to the audit table undo changes if there is an issue... zdb.Execute zssql, dbFailOnError ' 'move to the last record in tbl_audit... should be the just created record zrs.MoveLast ' 'open the record for edit and add the current date zrs.Edit zrs!audit_date = zddate zrs.Update ' z_clean_up_your_database: zrs.Close zdb.Close Set zdb = Nothing Set zrs = Nothing Exit Sub z_bad_error_nonono: MsgBox Err.Number & vbCrLf & Err.Description GoTo z_clean_up_your_database: End Sub
Now you have a copy of the old record with date changed... the rest is up to you :)
-z
Comment