Ms Access Tip: Keeping Up With User Activity

By: Jon Watson

At times you will find it very handy to know what a user was doing in your application at a specific time. This is especially useful with multi-user database applications for debugging or security reasons. With this tool implemented in your applications you will be able to see what event happened and at what time.

Here's the tip:

You are going to use a table and this simple set of code to record all the users transactions that you want to track. There are three simple steps to set this up in any application you develop. Create a table to hold the data, create a quick module, then add two lines of code to each operation you want to track such as a Form_Open or Form_Close event. That's it and you will find the information very useful.

Follow these simple steps and you will have a history of activity in your applications. Step one and two only have to be done once. Step 3 is needed for every event you want to track.

First create a simple table as described below:

1] Create a table to hold the user log information and name it USysLog.
Add these fields

Event as Text
EvTime as date/time

Save the table and name it USysLog and click No when asked to create a Key field

2] Create a module and add the following code. You can just cut and paste the following lines into a new module and save it using any name like LogMod.

'cut here
'Dimension a public variable at the top of the module.
Public LogEvent As String

'Next add this code in the module
Public LogEvent As String

Public Function LogEvt()
Dim SQL As String
SQL = "INSERT INTO UsysLog ( Event, EvTime ) SELECT '" & LogEvent & "' AS x1, #" & Now() & "# as x2;"
DoCmd.RunSQL SQL
End Function
'cut here

Close the module and save it as LogMod. (Name not important)

3] Next add these two lines of code to each event that you want to record a time for and edit the first line for the appropriate form name and event. In this example, you would see the text "Logon Opened" and an associated time in the UsysLog table.

LogEvent = " Logon Opened "
LogEvt

If you want to log a form opened time then put these lines in the "Form_Open" event and likewise if you want to log the form close time put it in the "Form_Closed" event and edit the wording on the first line accordingly. This way you will have a time stamp of the event in the UsysLog table with your own wording.

With multi-user databases we usually take it a step further and capture the user name with a login screen or the computer name (which can be done automatically) and drop that in the table as well so you know exactly who did the operation as well.

Please take a look at and see if you can't take advantage of all of the examples found in our Access Help Ebook to help you make your databases more robust.

Our Office Automation Services include solutions used by both large and small companies that are affordable and easy to use. Our products and services are proven to enable our customers to provide better service to their customers while saving them money in the process. Our customers find that their return on investment is most often realized after using their applications just a few times.

What could BioMation Systems do for you?

Go ahead, take another look.

Top Searches on
Technology
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Technology
 



Share this article :
Click to see more related articles