I am developing some logging for a multi-user DB my colleague built. I am a light VBA coder (self-taught).
Our Access MDB will be used for our User community to request changes to the key system-level data of a hosted application that is not connected to the MDB. Thus we are mimicking the Data Tables of the host system in Access. In fact, once this becomes operational, the source of truth for
these tables will be the Access Db, not the host system.
Our team will be reviewing the Change Requests, on a field by field basis, and either approve them or reject them. Once changes get approved, we will apply the changes to the official records in the Db representing what the host system should be. In other words, we do NOT want the official Access tables changed by the users when they submit them. We just want to create request data.
My first attempt was, when someone wanted to change an existing row's data via a form, saving the changed record right in the main table that the official data is in, but I would change the Primary Key to the next number in the sequence, thus creating a brand new record with a status of 'request.' I could not find a way to change the AUTONUMBER primary key field to use the next value in the sequence this way, so I set this aside.
Then I discovered the 'Creating an Audit Log' by Allen Browne
and this seemed promising. I was successful at getting the auditing to work on a sample table I am working with when user changes the row in the form. But I can not figure out a way to tweak it to let me NOT update the underlying table and just record in the Audit table. The details of my attempts are below.
Any ideas on how to log desired change requests, either by changing the AUTONUMBER Primary key in the form or by using the Audit Logs, without changing the underlying data rows until the requests are approved, would be appreciated. If I can not change the AUTONUMBER Primary key in the form I know I need a separate table to store the "requests" and the Audit Log table seems like a great way to do this since it would be easy to find which fields changed.
Another possibility is comparing the Textbox's OldValue to Current value and if changed, writing the details of change to a change table, but (Me.TextboxName.OldValue), but that requires a lot of control-by-control coding. Which is why using the Audit Log from Allen Browne was so desirable to use
Thanks in advance!
Allan
For all of following scenarios of Allen Brown's Audit Log, I commented out the line of VBA code in the SAVE button on the form which saves the data in the table.
I left the Audit Log code in the BEFORE & AFTER update events of the Form.
Changed rows via the form and clicked Save button, which saved the changed data in the regular table (WHICH I DO NOT WANT), but did record the audit data correctly.
Then With both sets of Audit Code for a Change in the BEFORE UPDATE event (I moved the AFTER UPDATE code into the BEFORE UPDATE code) and changed a row in the form, this still changed the official Table, WHICH I DO NOT WANT. It
created Audit records correctly.
With Both Sets of Audit Code in SAVE BUTTON and nothing in the form's Before/After Update events, I changed a row 7 This again changed the official Table, WHICH I DO NOT WANT. It created Audit records but the change are NOTreflected in the 'EditTo row.
And by not using the real SAVE command to create a new row in the primary table when the user wants to request a new row, I can not use this audit feature as the audit rows refer to the real table's primary key.
When above did not work, I then tried both legs of the audit code in the before update event which then had line
Cancel = True
after to stop the update to the table, but that did not work correctly. It does prevent update to the main table. Unfortunately, the new EditTo row in Audit log does not include the changes the user enters, it is same as EditFrom record for changed fields.
So the pseudo-code I need in the Before Update event of the form -- in order to use the Audit Log from Allen Browne is:
BEFORE UPDATE event
IF a changed row THEN
Run the Allen Browne Audit log in a tweaked way which will work without changing the table in the form
PREVENT THE CHANGE TO THE REGULAR TABLE
'CANCEL = True doe not work so I was trying to get record.Fields.CancelUpdate to work here
ELSE ........
Our Access MDB will be used for our User community to request changes to the key system-level data of a hosted application that is not connected to the MDB. Thus we are mimicking the Data Tables of the host system in Access. In fact, once this becomes operational, the source of truth for
these tables will be the Access Db, not the host system.
Our team will be reviewing the Change Requests, on a field by field basis, and either approve them or reject them. Once changes get approved, we will apply the changes to the official records in the Db representing what the host system should be. In other words, we do NOT want the official Access tables changed by the users when they submit them. We just want to create request data.
My first attempt was, when someone wanted to change an existing row's data via a form, saving the changed record right in the main table that the official data is in, but I would change the Primary Key to the next number in the sequence, thus creating a brand new record with a status of 'request.' I could not find a way to change the AUTONUMBER primary key field to use the next value in the sequence this way, so I set this aside.
Then I discovered the 'Creating an Audit Log' by Allen Browne
and this seemed promising. I was successful at getting the auditing to work on a sample table I am working with when user changes the row in the form. But I can not figure out a way to tweak it to let me NOT update the underlying table and just record in the Audit table. The details of my attempts are below.
Any ideas on how to log desired change requests, either by changing the AUTONUMBER Primary key in the form or by using the Audit Logs, without changing the underlying data rows until the requests are approved, would be appreciated. If I can not change the AUTONUMBER Primary key in the form I know I need a separate table to store the "requests" and the Audit Log table seems like a great way to do this since it would be easy to find which fields changed.
Another possibility is comparing the Textbox's OldValue to Current value and if changed, writing the details of change to a change table, but (Me.TextboxName.OldValue), but that requires a lot of control-by-control coding. Which is why using the Audit Log from Allen Browne was so desirable to use
Thanks in advance!
Allan
For all of following scenarios of Allen Brown's Audit Log, I commented out the line of VBA code in the SAVE button on the form which saves the data in the table.
I left the Audit Log code in the BEFORE & AFTER update events of the Form.
Changed rows via the form and clicked Save button, which saved the changed data in the regular table (WHICH I DO NOT WANT), but did record the audit data correctly.
Then With both sets of Audit Code for a Change in the BEFORE UPDATE event (I moved the AFTER UPDATE code into the BEFORE UPDATE code) and changed a row in the form, this still changed the official Table, WHICH I DO NOT WANT. It
created Audit records correctly.
With Both Sets of Audit Code in SAVE BUTTON and nothing in the form's Before/After Update events, I changed a row 7 This again changed the official Table, WHICH I DO NOT WANT. It created Audit records but the change are NOTreflected in the 'EditTo row.
And by not using the real SAVE command to create a new row in the primary table when the user wants to request a new row, I can not use this audit feature as the audit rows refer to the real table's primary key.
When above did not work, I then tried both legs of the audit code in the before update event which then had line
Cancel = True
after to stop the update to the table, but that did not work correctly. It does prevent update to the main table. Unfortunately, the new EditTo row in Audit log does not include the changes the user enters, it is same as EditFrom record for changed fields.
So the pseudo-code I need in the Before Update event of the form -- in order to use the Audit Log from Allen Browne is:
BEFORE UPDATE event
IF a changed row THEN
Run the Allen Browne Audit log in a tweaked way which will work without changing the table in the form
PREVENT THE CHANGE TO THE REGULAR TABLE
'CANCEL = True doe not work so I was trying to get record.Fields.CancelUpdate to work here
ELSE ........