[RESOLVED] Access 2010 BeforeDelete data macro vs. VB.Net
Hi -
I'm not sure if this is the right forum to post my question, but I think it fits the general topic. Hopefully somebody can help me out.
I have an Access 2010 back-end db with several tables. Each table in my db uses its AfterInsert and AfterUpdate event-driven macros ("data triggers") to capture information (table inserts and field changes) and send that information to a named macro in the "Change Log" table. The named macro then creates a new record (audit trail) in the Change Log table. This all is working well.
I have not been able to figure out how to use the BeforeDelete data macro on a table in my back-end db to capture the to-be-deleted record's information (e.g., its primary key and one or more field values) and then send that information to the Change Log's named macro which would then create a new record in the Change Log table with the deleted record's information.
The drop-down list of available Access 2010 macro commands for the BeforeDelete data macro does not include the RunDataMacro command (like the AfterInsert and AfterUpdate data macros). The AfterDelete data macro is not an option because the record has already been delete by the time the macro is "fired" by the record deletion event.
So, I have instead resorted to code in the application's front-end UI (a VB.Net project) to insert records into the back-end db's Change Log table before a record is deleted. As you might imagine, this complicates things (e.g., cascaded record deletions via referential integrity rules can't happen -- instead I must perform each record deletion one-by-one to record the audit trail information for each to-be-deleted record).
Am I missing something here?
Thanks to anyone who might have some advice.
Re: Access 2010 BeforeDelete data macro vs. VB.Net
I have answered my own question! The to-be-deleted database record has not yet been deleted when the data macro's AfterDelete event fires. What was leading me astray was that I'm used to the Access VBA form events (BeforeDelete, BeforeDelConfirm, and AfterDelConfirm). Unlike the form events where the to-be-deleted record is moved to a temporary buffer, the data macro AfterDelete event still has visibility to the to-be-deleted record (the record is deleted after this event is complete).
The AfterDelete data macro event has a full compliment of macro commands, like the BeforeInsert and BeforeUpdate events -- including the RunDataMacro command. So I am able to capture the to-be-delete table record's fields in an audit trail.
Problem solved...