I am trying to do an audit trail in Microsoft Access and I need a way to track when users open a table, not a form. Is there a way to run a function every time a table is opened?
-
I don't think there is. If you need this sort of auditing, you most certainly shouldn't give users the means to open tables directly. – Andre Sep 12 '20 at 12:03
-
@Andre isn't it the general rule to not allow users access to tables/queries, only forms/reports? AT Marquan because of several downsides (e.g. backups), you shouldn't use accdb files as backend. With e.g SQL-Server, you can audit almost everything. – ComputerVersteher Sep 12 '20 at 12:26
-
Since access 2010, there are table triggers and store procedures in the database engine. however, these triggers only fire on updates/inserts, not just a open table. As noted, to track "just" the act of opening a table is quite difficult. in fact, I don't think you can even do this with sql server. – Albert D. Kallal Sep 12 '20 at 13:40
-
@ComputerVersteher - how can you with SQL server track that a table was just opened? (I did not realize that feature existed in sql server). For updates, inserts etc? Sure you can do that - even in Access at the table trigger level, but not just the act of having opened or used a table. This would have to be done at code/UI level, not database engine level. And this suggestion would not be limited to Access, but would be a problem for most if not all modern data engines. I suppose one could turn on tracing, but that's way too high of a server load. – Albert D. Kallal Sep 12 '20 at 13:47
2 Answers
Unfortunately, no events are fired when opening tables or queries in a MS Access database. If you do need to have this functionality, there are two options that I can think of, both involve hiding or restricting direct access to the tables:
Build a dashboard form, with a command button to open each table and use the
Click
event of the button to perform your auditing procedure. you'll be able to audit the opening of each table, but not closing. Use database table triggers to do the audit of data updates.Create datasheet view forms of all your tables, and give access to these forms to the user instead of the tables. You'll be able to use all the supported form events to perform your audit, such as opening, closing, data updates.
You can build a combination of both to achieve your goal.

- 694
- 5
- 7
Unfortantly this would have to be done at the UI or application level, not the data engine level. Access since 2010 does have table events and procedural code that can run at the engine level (store procedures). These table triggers and procedural code run independent of Access, and VBA code. In fact if .net or outside applications (non access) even update Access tables with ODBC, then these table triggers and store procedure code will run.
So, these features in the Access data engine (ACE) would allow some kind of audit trail and logging system to be created.
However, JUST WHO opens a table? No, that feature is not available in even SQL server, and most data engines don't have this ability (with the exception of trace features, but these are for testing, and debugging, and cause significant slow downs if such kinds of "logging" is turned on. In fact, ACE also has what is called show-plan. This will show the query plan used by ACE data engine for each and every query. But again, as noted, this kind of logging is for debugging and not suitable for tracking the "act" of a table open.
However, like SQL server, the Access data engine does have table event triggers, but they only run for updates, inserts, deletes.
Even with SQL server, you are limited to such table events. To be fair, SQL server does also have events for "DML" operations (ACE does not). So, drop of tables, or even schema modifications can fire events, the Access ACE engine cannot.
All in all? Even with SQL server, to track/log who opend what table? You quite much need to do this at the UI/applicaiton level and not the data engine level.
If the Access application is built well, then users will never open a table directly anyway - and this holds true for any well written program - you never open/use tables directly anyway the instant you build a application in Access as opposed to just editing and view some tables like how one would in say Excel.
So, you would have to attach some code in the forms on-load. It is quite common to do this, and in several applications, we for example have a "edit" button on a form. The form can be viewed, but to edit, you have to first un-lock. When you click on un-lock, then that event is logged. As a result, we can see a nice list of all users (people) who editing that record. But, we don't log "just" the act of having opened and view the form that displays data from the table.
However, it certainly would be possible to log, and track such actions, but as noted, this would occur at the application level - not data engine level.

- 42,205
- 3
- 34
- 51
-
[How to see query history in SQL Server Management Studio](https://stackoverflow.com/questions/5299669/how-to-see-query-history-in-sql-server-management-studio) – ComputerVersteher Sep 13 '20 at 05:25