Connecting Tech Pros Worldwide Forums | Help | Site Map

Track changes to a record in Access

Newbie
 
Join Date: Apr 2007
Posts: 14
#1: Nov 8 '07
Hi,

I'm creating a database and I need to find a way to track the changes to a record, more exactly, I need to know who makes changes to each record, as the users can only modify their own records.

I have one table where all the data is stored and I have between 50-100 users. Due to the high number of users, I would like to use the Windows login user ID instead of having to create user ID in Access. Is it possible? If yes, what is the code to be able to get the information (who changed the record) added to my table?

Thank you!

Marie

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,223
#2: Nov 9 '07

re: Track changes to a record in Access


Quote:

Originally Posted by zoro25

Hi,

I'm creating a database and I need to find a way to track the changes to a record, more exactly, I need to know who makes changes to each record, as the users can only modify their own records.

I have one table where all the data is stored and I have between 50-100 users. Due to the high number of users, I would like to use the Windows login user ID instead of having to create user ID in Access. Is it possible? If yes, what is the code to be able to get the information (who changed the record) added to my table?

Thank you!

Marie

Marie, you can create a Log File that Tracks which Logged User made changes to data in a specific Form, at a give Date and Time, and it will also list the Primary Key Number of the Record that was changed. Copy and Paste the following Sub-Routine in a Standard Code Module. In its simplest Format, it will create a Log File in C:\Changes.txt that will list the changes made in order. Place the Sub Procedure Call in the AfterUpdate() Event of any Form for which you want to track data modifications:
Expand|Select|Wrap|Line Numbers
  1. Public Sub TrackChanges(strUser As String, frmName As String, lngPrimaryKey)
  2. Dim Msg As String
  3.  
  4. Msg = Format$(Now(), "dddd, mm/dd/yyyy hh:mm AM/PM") & " - "
  5. Msg = Msg & strUser & " made changes to data in Form " & frmName
  6. Msg = Msg & " - {Primary Key Number " & lngPrimaryKey & "}"
  7.  
  8. Open "C:\Changes.txt" For Append As #1
  9. Print #1, Msg
  10.  
  11. Close #1
  12. End Sub
  13.  
Sample Call to the Sub-Routine
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.   Call TrackChanges(CurrentUser(), "frmEmployee", Me![PrimaryKey])
  3. End Sub
  4.  
Sample from C:\Changes.txt
Expand|Select|Wrap|Line Numbers
  1. Thursday, 11/08/2007 10:39 PM - Admin made changes to data in Form frmInventory - {Primary Key Number 74}
  2. Thursday, 11/08/2007 11:48 PM - John Doe  made changes to data in Form frmEmployee - {Primary Key Number 98774}
  3. Friday, 11/09/2007 08:05 AM - Bart Simpson made changes to data in Form frmInvoice - {Primary Key Number 876}
  4.  
NOTE: The above code was listed only as a simple Template, make your own changes to suit your specific needs.
Member
 
Join Date: Oct 2007
Posts: 42
#3: Nov 11 '07

re: Track changes to a record in Access


Quote:

Originally Posted by zoro25

Hi,

I'm creating a database and I need to find a way to track the changes to a record, more exactly, I need to know who makes changes to each record, as the users can only modify their own records.

I have one table where all the data is stored and I have between 50-100 users. Due to the high number of users, I would like to use the Windows login user ID instead of having to create user ID in Access. Is it possible? If yes, what is the code to be able to get the information (who changed the record) added to my table?

Thank you!

Marie

Hello Marie,

Take a look at my blog entry
Tracking changes in Access
this should do what you need.

Bill Mitchell
Reply