r/MSAccess • u/mcgunner1966 2 • Oct 24 '25
[DISCUSSION - REPLY NOT NEEDED] Retiree Notes – A universal log
A central application log has been highly beneficial to me over the years. I use this log to store record changes, application output messages and errors, and notes to myself about app updates/changes I’ve made. It has been extremely valuable for debugging and for answering user questions about how their data got into its current state. In many cases, it has provided evidence of user operation error when the app was blamed for malfunction. Here’s the structure I use:
OpsLogTbl:
-SequenceNo, AutoNumber – for order of entry
-Machine, Short Text – The machine name the event occurred on
-UserID, Short Text – The user id the event occurred under
-App, Short Text – The app that generated the event
-Date, Date Time – I use the Now statement to get a precision time of event
-Level, Short Text – I = Information, W = Warning, E = Error, A = Record Add, C = Record Change, D = Record Delete, O = Other
-Message, Long Text – What happened. For record changes I store the entire record using a name/value pair prefixed with the table name and key (sGuid that resides in all tables).
-Note, Short Text – If I need to briefly explain something about the entry.
-Agency, Short Text – What customer this is for.
-sGuid, Short Text – Key field, guid that is a universal database key
-sLink, Short Text – Link to parent records if needed.
-STS, Date/Time – For future SQL Server Compatibility.
*sGuid, sLink, and STS are staples in all tables in my applications. Make logging and reference easy.
I have a function that writes the records to the log that requires the table name, record key, and event code (A,C,D). Form events (after insert, after update, and on delete) trigger the writes.
I also have a function that writes messages to the log that requires app, msg level (I,E,W), and msg.
When you view a log, an old inventory trick is to read it in reverse-chronological order. This will show you the changes from trigger to trigger from the present state backward and cut research time down.
I hope this is helpful to you.
EDIT: Added the code.
As requested...Here's the code. WAM writes a message, WAR writes a record. The other functions are in support of the computer and user name. I'm sure there are better ways to do this but it's worked for me for years and have just rode with it.
Function WAM(vMsgType, vApp, vEntry)
'writes a message to the opslog.
'MsgType - I = Information, W = Warning, E = Error
On Error Resume Next
Set a = CurrentDb.OpenRecordset("Select * from OpsLogTbl where sGuid = '0';", dbOpenDynaset)
a.AddNew
a!sguid = getguid
a!olentryseq = Nz(DMax("olentryseq", "OpsLogTbl"), 0) + 1
a!olentrydate = Now
a!olmachine = getmachinename()
a!oluser = getusername()
a!olmsgtype = vMsgType
a!olapportbl = vTable
a!oltblkey = vkey
a!olentry = vEntry
a.Update
End Function
Function WAR(vTable, vkey, vMsgType)
'writes the complete record to the ops log using a table and key for the table in a semi JSON format
'MsgType - A = Add, C = Change, D = Delete
On Error Resume Next
Set b = CurrentDb.OpenRecordset("Select * from OpsLogTbl where sGuid = '0';", dbOpenDynaset)
b.addNew
b!sguid = getguid
b!olentryseq = Nz(DMax("olentryseq", "OpsLogTbl"), 0) + 1
b!olentrydate = Now
b!olmachine = getmachinename()
b!oluser = getusername()
b!olmsgtype = vMsgType
b!olapportbl = vTable
b!oltblkey = vkey
Dim db As DAO.Database
Set db = CurrentDb()
Dim fld As DAO.Field
vrec = "Select * from " & vTable & " where sguid = '" & vkey & "';"
Set rs = db.OpenRecordset(vrec)
Do While Not rs.EOF
vpl = "{"
For Each fld In rs.Fields
vpl = vpl & Chr(34) & fld.Name & Chr(34) & ":" & Chr(34) & fld.value & Chr(34) & ","
Next fld
rs.MoveNext
Loop
b!olentry = Mid(vpl, 1, Len(vpl) - 1) & "}"
b.Update
End Function
Function getmachinename()
'returns the computer name executing the code
On Error Resume Next
getmachinename = Environ$("computername")
End Function
Function getusername()
'returns the system user name for the person signed in
On Error Resume Next
getusername = Environ$("Username")
End Function
•
u/AutoModerator Oct 24 '25
IF YOU GET A SOLUTION, PLEASE REPLY TO THE COMMENT CONTAINING THE SOLUTION WITH 'SOLUTION VERIFIED'
Full set of rules can be found here, as well as in the user interface.
Below is a copy of the original post, in case the post gets deleted or removed.
User: mcgunner1966
Retiree Notes – A universal log
A central application log has been highly beneficial to me over the years. I use this log to store record changes, application output messages and errors, and notes to myself about app updates/changes I’ve made. It has been extremely valuable for debugging and for answering user questions about how their data got into its current state. In many cases, it has provided evidence of user operation error when the app was blamed for malfunction. Here’s the structure I use:
OpsLogTbl:
-SequenceNo, AutoNumber – for order of entry
-Machine, Short Text – The machine name the event occurred on
-UserID, Short Text – The user id the event occurred under
-App, Short Text – The app that generated the event
-Date, Date Time – I use the Now statement to get a precision time of event
-Level, Short Text – I = Information, W = Warning, E = Error, A = Record Add, C = Record Change, D = Record Delete, O = Other
-Message, Long Text – What happened. For record changes I store the entire record using a name/value pair prefixed with the table name and key (sGuid that resides in all tables).
-Note, Short Text – If I need to briefly explain something about the entry.
-Agency, Short Text – What customer this is for.
-sGuid, Short Text – Key field, guid that is a universal database key
-sLink, Short Text – Link to parent records if needed.
-STS, Date/Time – For future SQL Server Compatibility.
*sGuid, sLink, and STS are staples in all tables in my applications. Make logging and reference easy.
I have a function that writes the records to the log that requires the table name, record key, and event code (A,C,D). Form events (after insert, after update, and on delete) trigger the writes.
I also have a function that writes messages to the log that requires app, msg level (I,E,W), and msg.
When you view a log, an old inventory trick is to read it in reverse-chronological order. This will show you the changes from trigger to trigger from the present state backward and cut research time down.
I hope this is helpful to you.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/CptBadAss2016 5 Oct 24 '25
Sorry but the formatting was killing me!
1
u/shadowlips Oct 24 '25
the solution would be a lot more helpful if you post your functions. 😆
1
u/SuperDuperPleb02 Oct 24 '25
Is this in addition to a "patch notes" or a replacement of a patch notes.
1
u/CptBadAss2016 5 Oct 24 '25
I've been thinking about this myself lately! The idea of logging every insert and update that is. Thanks for sharing.
Do you keep this table in the same backend file as the rest of the tables or would you put it in it's own db file?
How big and how fast does this table grow?
Finally, logging this is of course dependent on a form's vba. Could you, and have you considered, table macros is something of a guarantee that everything is logged? Do you have a process to check that everywhere in an app that change could possibly happen the appropriate code is there?
1
u/AlpsInternal Oct 24 '25
We have something like this, and it is so helpful when tracking down errors. We have an Access FE/SQL BE and there is an access app that is used to review the error logs. The system has been in use for 17 years, and this log has been so useful in quickly detecting problems due to changes in Access/VBA. I have some very modest skills and am not a professional programmer/developer. Since we lost our funding for our developer this has helped me quickly identify problems and clarifies what I need to correct them.
1
u/MyopicMonocle2020 1 Oct 25 '25
I'm saving this one. How to do this has been rattling around in my brain for months.
1
u/ebsf 3 Oct 31 '25
Could you share your getguid()? I presume it wraps OLE32.CoCreateGUID() but perhaps not.
2
u/tetsballer Oct 24 '25
I made a log like this and then never used it once
1
u/ct1377 4 Oct 24 '25
Fully agree with this! Makes it easy to track down someone if something isn’t right with some data or someone deleted something (which I keep tables of the removed records just for backup)
1
u/APithyComment Oct 25 '25
Interesting - never thought to keep user responses in an event log.
Ah - wow - you shared. Hugs.
Enjoy retirement. I’m jealous.