473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tracked user name using basAuditTrail module.

Hi there,

I'm using this audit trail code (basAuditTrail module) to log changes in my database, but I'm needing it to track by the user name logged into Access not by the account logged into Windows. Does anybody know how to change this?

Your help would be much appreciated.
Thanks heaps.

Phil.

This is the code I'm using....it seems to be a common one found in forums.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   Call AuditTrail(Me, RecordNo) 'RecordNo is the primary key for each table 
  3. End Sub
In (module) basAuditTrail:
Expand|Select|Wrap|Line Numbers
  1. Const cDQ As String = """"
  2.  
  3. Sub AuditTrail(frm As Form, recordid As Control)
  4.   'Track changes to data.
  5.   'recordid identifies the pk field's corresponding
  6.   'control in frm, in order to id record.
  7.   Dim ctl As Control
  8.   Dim varBefore As Variant
  9.   Dim varAfter As Variant
  10.   Dim strControlName As String
  11.   Dim strSQL As String
  12.   On Error GoTo ErrHandler
  13.   'Get changed values.
  14.   For Each ctl In frm.Controls
  15.     With ctl
  16.       'Avoid labels and other controls with Value property.
  17.       Select Case ctl.ControlType
  18.         Case acTextBox, acCheckBox, acComboBox
  19.           If .Value <> .OldValue Then
  20.             varBefore = .OldValue
  21.             varAfter = .Value
  22.             strControlName = .Name
  23.             'Build INSERT INTO statement.
  24.             strSQL = "INSERT INTO " _
  25.                 & "tblAudit (EditDate, User, RecordID, SourceTable, " _
  26.                 & " SourceField, BeforeValue, AfterValue) " _
  27.                 & "VALUES (Now()," _
  28.                 & cDQ & Environ("username") & cDQ & ", " _
  29.                 & cDQ & recordid.Value & cDQ & ", " _
  30.                 & cDQ & frm.RecordSource & cDQ & ", " _
  31.                 & cDQ & .Name & cDQ & ", " _
  32.                 & cDQ & varBefore & cDQ & ", " _
  33.                 & cDQ & varAfter & cDQ & ")"
  34.             'View evaluated statement in Immediate window.
  35.             Debug.Print strSQL
  36.             DoCmd.SetWarnings False
  37.             DoCmd.RunSQL strSQL
  38.             DoCmd.SetWarnings True
  39.           End If
  40.       End Select
Apr 24 '08 #1
1 2602
missinglinq
3,532 Expert 2GB
CurrentUser() returns the Access user name. Try substituting for Environ("username") in your code.

Welcome to bytes!

Linq ;0)>
Apr 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Egil M?ller | last post by:
I'm developing a larger Python program, and one component (a text parser for a networking protocol) happend to be terribly slow, while quite a simple piece of code, so I decided to reimplement it...
3
by: Martin Lacoste | last post by:
Wondering if people have suggestions as to good reference sources for Access 2000 for an (almost..) intermediate user? It appears as though books along the lines of 'Access for Dummies' are way...
10
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
6
by: Cameron Walsh | last post by:
Hi, I'm writing a python program to analyse and export volumetric data. To make development and extension easier, and to make it more useful to the public when it is released (LGPL), I would...
3
by: hary08 | last post by:
im doing a database for Hospital Admission, I have a log in form which prompt user for a password. The source of log in is to look for the values in my Table tblEmployees and match user name and...
3
by: T | last post by:
I'm trying to determine the useage of varioius reports I have. I need the following to occur when a report is opened, get the name of the report, datetime, username. I created a tblLog...
0
by: Gert | last post by:
Inside my workflow "Workflow1" in CodeActivity "startActivity" I do : this.TrackData("Key", "value"); I can see in my SQL SqlPersistence DB in the UserEvent table the tracking value was added....
5
topher23
by: topher23 | last post by:
I've seen a lot of questions about how to make secure database passwords. I'm going to go over a method of encrypting a password using the MD5 encryption algorithm for maximum security. First,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.