473,732 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Audit trail question

Helllo--I have implemented the audit trail from the Microsoft KB
article that records changes on a data entry form to a memo filed in
the fieeld's table record. What I would like to do is pull certain
info from that module and put it in a separate table--is this
possible?
tHANKS,
bOB
Explanations in caps in code

Function AuditTrail()
On Error GoTo Err_Handler
Dim MyForm As Form, C As control, xName As String

THESE ARE THE VARIABLES i WOULD LIKE TO TRANSFER
Dim pid As String
Dim fieldname As String
Dim oldval As String
Dim newval As String
Dim formname As String

Set MyForm = Screen.ActiveFo rm
'Set date and current user if form has been updated.
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"Changes made on " & Date & " by " & CurrentUser() & ";"

'If new record, record it in audit trail and exit.
If MyForm.NewRecor d = True Then
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"New Record """
Exit Function
End If
'Check each data entry control for change and record old value of
Control.

For Each C In MyForm.Controls
'Only check data entry type controls.
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup
' Skip Updates field.
If C.name <> "Updates" Then
' If control was previously Null, record "previous
' value was blank." NOT RECORDING THIS BUT LEFT CODE IN IN
CASE I CHANGE MIND
If IsNull(C.OldVal ue) Or C.OldValue = "" Then
End If
' MyForm!Updates = MyForm!Updates & Chr(13) & _
' Chr(10) & C.name & "--previous value was blank"

' If control had previous value, record previous value.
' Else
If C.Value <> C.OldValue Then
MyForm!Updates = MyForm!Updates & Chr(13) &
Chr(10) & _
C.name & "==previous value was " & C.OldValue

i WANT TO CAPTURE THESE VALUES BEFORE GOING TO THE NEXT CONTROL AND
TRANSFER THEM TO A SEPARATE TABLE HERE--CAN i DO THIS???
pid = MyForm!PatId
formname = MyForm.name
fieldname = C.name
oldval = C.OldValue
newval = C.Value

End If
End If
End Select
Next C

TryNextC:
Exit Function

ERROR HANDLING OMITTED FOR THIS MESSAGE

Nov 13 '05 #1
8 1977
sure. pass all the data you want to another function that writes it to
another table by opening a recordset and appending the data...

public function LogOldAndNewVal ues( lngPID As Long, strForm as string,
strField As String, varOldValue as Variant, varNewValue as Variant)
dim rs as dao.recordset
set rs=dbengine(0)( 0).openrecordse t("LogTable",db opentable)
rs.addnew
rs.fields("PID" )=lngPID
rs.fields("Form Name")=strForm
rs.fields("OldV alue")=varOldVa lue
rs.Fields("NewV alue")=varNewVa lue
rs.update
rs.close
set rs=nothing

end function

Nov 13 '05 #2
Thanks--will try it at work Monday

bob
On 15 Apr 2005 20:37:55 -0700, pi********@hotm ail.com wrote:
sure. pass all the data you want to another function that writes it to
another table by opening a recordset and appending the data...

public function LogOldAndNewVal ues( lngPID As Long, strForm as string,
strField As String, varOldValue as Variant, varNewValue as Variant)
dim rs as dao.recordset
set rs=dbengine(0)( 0).openrecordse t("LogTable",db opentable)
rs.addnew
rs.fields("PID ")=lngPID
rs.fields("For mName")=strForm
rs.fields("Old Value")=varOldV alue
rs.Fields("New Value")=varNewV alue
rs.update
rs.close
set rs=nothing

end function


Nov 13 '05 #3
HI--and thanks for the code--I got it to work with a few changes---I
included your code within the audit trail modul--when I tried to call
it as a separate function it was not passing the values to the audit
log table so I declared the variables in the original module and then
assigned them the desired value(strformna me = myform.name for
example)--thanks again for your help

On 15 Apr 2005 20:37:55 -0700, pi********@hotm ail.com wrote:
sure. pass all the data you want to another function that writes it to
another table by opening a recordset and appending the data...

Function AuditTrail()
On Error GoTo Err_Handler
Dim MyForm As Form, C As control, xName As String
lngPID As Long
strForm as string
strField As String
varOldValue as Variant
varNewValue as Variant
Set MyForm = Screen.ActiveFo rm

MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"Changes made on " & Date & " by " & CurrentUser() & ";"

If MyForm.NewRecor d = True Then
MyForm!Updates = MyForm!Updates & Chr(13) & Chr(10) & _
"New Record """
Exit Function
End If

For Each C In MyForm.Controls
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup

If C.name <> "Updates" Then
If IsNull(C.OldVal ue) Or C.OldValue = "" Then
End If
' MyForm!Updates = MyForm!Updates & Chr(13) & _
If C.Value <> C.OldValue Then
MyForm!Updates = MyForm!Updates & Chr(13) &
Chr(10) & _ C.name & "==previous value was " & C.OldValue
lngpid = MyForm!PatId
strformname = MyForm.name
strfieldname = C.name
varoldval = C.OldValue
varnewval = C.Value dim rs as dao.recordset
set rs=dbengine(0)( 0).openrecordse t("LogTable",db opentable)
rs.addnew
rs.fields("PID ")=lngPID
rs.fields("For mName")=strForm
rs.fields("Old Value")=varOldV alue
rs.Fields("New Value")=varNewV alue
rs.update
rs.close
set rs=nothing

End If
End If
End Select
Next C

TryNextC:
Exit Function

Nov 13 '05 #4
On 15 Apr 2005 20:37:55 -0700, pi********@hotm ail.com wrote:
sure. pass all the data you want to another function that writes it to
another table by opening a recordset and appending the data...

public function LogOldAndNewVal ues( lngPID As Long, strForm as string,
strField As String, varOldValue as Variant, varNewValue as Variant)
dim rs as dao.recordset
set rs=dbengine(0)( 0).openrecordse t("LogTable",db opentable)
rs.addnew
rs.fields("PID ")=lngPID
rs.fields("For mName")=strForm
rs.fields("Old Value")=varOldV alue
rs.Fields("New Value")=varNewV alue
rs.update
rs.close
set rs=nothing

end function


Hi--i took your function above and included it in the first function.
It works quite well but am haviung one problem. If the old value or
new value is null then a record is not being created. With the code
below it is creating an aurdit record for each control on my form--If
the oldvalue and new value are both null then I want to move to the
next control without creating an audit record for that control I can't
figure out where to put apropiate code--see below:
Dim MyForm As Form, C As control, xName As String
Dim strPatID As String
Dim strForm As String
Dim strField As String
Dim varOldValue As Variant
Dim varNewValue As Variant
Set MyForm = Screen.ActiveFo rm

SNIPPED OTHER STUFF
For Each C In MyForm.Controls
'Only check data entry type controls.
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox

' If control was previously Null, do something
HERE IS WHERE I WANT TO CHECK FOR NULLS AND AND STILL CREATE RECORD
FOR CHANGES
If (IsNull(C.OldVa lue) Or C.OldValue = "") And (C.Value = ""
Or IsNull(C.Value) ) Then

WANT TO MOVE TO NEXT CONTROL WITHOUT CREATING AUDIT RECORD

Else
If (IsNull(C.OldVa lue) Or C.OldValue = "") And (C.Value <> ""
Or Not IsNull(C.Value) ) Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
varOldValue = 888
varNewValue = C.Value

ElseIf C.Value <> C.OldValue And (C.OldValue <> "" Or
Not IsNull(C.OldVal ue)) Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
varOldValue = C.OldValue
varNewValue = C.Value
End If

Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = DBEngine(0)(0). OpenRecordset(" test", dbOpenTable)
rs.AddNew
rs.Fields("PatI d") = strPatID
SNIPPED OTHER FIELDS ADDED
rs.Update
rs.Close
Set rs = Nothing

End If
End Select

Next C

End Function
THANKS
bob


Nov 13 '05 #5

I am trying to pass a value (888( to my audit trail table when either
the old value or new value is null. Below is what I came up with but
it does not create a record in the audit table for the nulls--only for
the non-null recs. Can anyone help me out with this issue? What am I
doing Wrong?

thanks
bob
If C.Value <> C.OldValue Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
THESE TRANSFER INTO TABLE FINE

THESE DO NOT
If IsNull(C.OldVal ue) Or C.OldValue = "" Then varOldValue = 888 Else
varOldValue = C.OldValue
If IsNull(C.Value) Or C.Value = "" Then varNewValue = 888 Else
varNewValue = C.Value

Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = DBEngine(0)(0). OpenRecordset(" test", dbOpenTable)

rs.AddNew
rs.Fields("PatI d") = strPatID
rs.Fields("staf f") = CurrentUser
rs.Fields("form name") = strForm
rs.Fields("fiel dname") = strField
rs.Fields("OldV alue") = varOldValue
rs.Fields("newv alue") = varNewValue
rs.Update
rs.Close
Set rs = Nothing
End If
Nov 13 '05 #6
What is the data type: text or numeric?

If text, try:

If Len(Trim$(C.Old Value & "")) = 0 Then
varOldValue = "888"
Else
varOldValue = C.OldValue
End If

If numeric, try:

varOldValue = Nz(C.OldValue, 888)
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

<al*****@cox.ne t> wrote in message
news:tb******** *************** *********@4ax.c om...

I am trying to pass a value (888( to my audit trail table when either
the old value or new value is null. Below is what I came up with but
it does not create a record in the audit table for the nulls--only for
the non-null recs. Can anyone help me out with this issue? What am I
doing Wrong?

thanks
bob
If C.Value <> C.OldValue Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
THESE TRANSFER INTO TABLE FINE

THESE DO NOT
If IsNull(C.OldVal ue) Or C.OldValue = "" Then varOldValue = 888 Else
varOldValue = C.OldValue
If IsNull(C.Value) Or C.Value = "" Then varNewValue = 888 Else
varNewValue = C.Value

Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = DBEngine(0)(0). OpenRecordset(" test", dbOpenTable)

rs.AddNew
rs.Fields("PatI d") = strPatID
rs.Fields("staf f") = CurrentUser
rs.Fields("form name") = strForm
rs.Fields("fiel dname") = strField
rs.Fields("OldV alue") = varOldValue
rs.Fields("newv alue") = varNewValue
rs.Update
rs.Close
Set rs = Nothing
End If

Nov 13 '05 #7
Thanks--the one problem though will be that the data type can
change--I am looping through each control on a form. I have the code
in an if-then staement but it is not transferring to the new variables
:(

bob

On Sat, 14 May 2005 11:33:49 -0400, "Douglas J. Steele"
<NOSPAM_djsteel e@NOSPAM_canada .com> wrote:
What is the data type: text or numeric?

If text, try:

If Len(Trim$(C.Old Value & "")) = 0 Then
varOldValue = "888"
Else
varOldValue = C.OldValue
End If

If numeric, try:

varOldValue = Nz(C.OldValue, 888)


Nov 13 '05 #8
I found a way to asign the null regardless of type--created temp
variables to hold the old and new value, tested them for nulls and
thenchecked teh temp variables for inequality, then performed needed
function-- and now it creates a rec in my audit table inclduing for
nulls (nulls are coded as 888)- I needed to be able to record if data
was replaced with a null or empty string--below is the
code--suggestions or comments appreciated.
Option Compare Database
Function AuditTrail()
Dim MyForm As Form, C As control, xName As String
Dim strPatID As String
Dim strForm As String
Dim strField As String
Dim varOldValue As Variant
Dim varNewValue As Variant
Dim tempold As Variant
Dim tempnew As Variant

Set MyForm = Screen.ActiveFo rm

For Each C In MyForm.Controls

If IsNull(C.OldVal ue) Or C.OldValue = "" Then tempold = 888 Else
tempold = C.OldValue

If IsNull(C.Value) Or C.Value = "" Then tempnew = 888 Else tempnew =
C.Value

If tempnew <> tempold Then
strForm = MyForm.name
strField = C.name
strPatID = MyForm!patid
varOldValue = tempold
varNewValue = tempnew

Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = DBEngine(0)(0). OpenRecordset(" test", dbOpenTable)

rs.AddNew
rs.Fields("PatI d") = strPatID
ETC, ETC
rs.Update
rs.Close
Set rs = Nothing
End If

End Select
Next C

TryNextC:
Exit Function
End Function


On Sat, 14 May 2005 11:33:49 -0400, "Douglas J. Steele"
<NOSPAM_djsteel e@NOSPAM_canada .com> wrote:
What is the data type: text or numeric?

If text, try:

If Len(Trim$(C.Old Value & "")) = 0 Then
varOldValue = "888"
Else
varOldValue = C.OldValue
End If

If numeric, try:

varOldValue = Nz(C.OldValue, 888)


Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7228
by: Raphael Gluck | last post by:
Hi, Is it possible for one to program one's pages as such that when a database table is updated over the web, via a form, that an e-mail confirmation is sent to a specified address, notifying the update has taken place? If so is there a tutorial out there that is easy to understand and implement? Thanks so much
2
1899
by: Keith | last post by:
Hi I am developing an ASP application which will interact with a SQL database. A requirement of the application is that there is a full audit trail of any modifications to data. I am struggling a bit to get my head round how to do this - just the concept.
0
1468
by: Me | last post by:
Hi... A much lamented question, I guess.. I'm trying to create a simple audit trail. log the changes to an SQL 2000 table, so that they are written into a mirror table. The entire record, only the updated one, i.e. if say only one field changes, the audit table will be inserted with one record that has one field changed. if the record has been deleted, it still will be written. I'm not worrying about additional fields to the audit...
3
2734
by: Me | last post by:
Hi... A much lamented question, I guess.. I'm trying to create a simple audit trail. log the changes to an SQL 2000 table, so that they are written into a mirror table. The entire record, only the updated one, i.e. if say only one field changes, the audit table will be inserted with one record that has one field changed. if the record has been deleted, it still will be written. I'm not worrying about additional fields to the audit...
3
6291
by: Zlatko Matić | last post by:
Hello. I tried to implement audit trail, by making an audit trail table with the following fileds: TableName,FieldName,OldValue,NewValue,UpdateDate,type,UserName. Triggers on each table were set to do the job and everything was fine except that in the audit trail you couldn't know which row exacltly was updated/inserted/deleted...Therefore I introduced 3 additional columnes (RowMark1, RowMark2, RowMark3) which should identify the...
5
2505
by: bruboj | last post by:
I created an audit trail for my access 97 database using code I found at: http://members.iinet.net.au/~allenbrowne/AppAudit.html One of the limitations stated for the code is "each table to be audited must have an AutoNumber primary key". Can someone explain why the automunber field has to be the primary key? It seems that the autonumber field would be unique by default. I have another field that needs to be unique but there is nothing...
6
5844
by: Parag | last post by:
Hello, I have been assigned the task to design the audit trail for the ASP.NET web application. I don't know what the best practices for such audit trails are. Our application one dedicated user name and password to perform the database operations. I need to capture all the operations which are performed on the database. Also I need to able to capture the operations which directly performed on the backend directly using the tools like...
6
2348
by: philmgron | last post by:
Hello I have been hitting my head against the wall on this problem for a day now. I have a simple table that stores cities, on of the fields on the table is modified_by. I am trying to write the user who modifed the table, in to the column modified_by. Code for getting the user that i am using is environ("username"), it works fine; however for the life of me i cannot figure out one which even to do this. This is how the form is...
3
3782
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 password entered.My case now is I have Audit Trail Module which keeps records of modifications and current user, I wanted my audit trail to log the current user based on who has log from based on my Log in Form.please help ty HERES THE CODE FOR ON...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.