473,387 Members | 1,464 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.

Audit Trail not working in subform...

Hi All,

I found this brilliant sample database posted on this fourm. It is working fine as for as the main form is concerned.

Does not do the updates in the subform. How do I do it?

In this case if I make any changes in fEmployees it is working. If I make change in fEmpPartner, it is putting a string in the main table "Changes made on 7/05/2011 1:21:53 PM by Admin;" Nothing more.

Thanks...

Raghu
Attached Files
File Type: zip AuditTrail.zip (24.0 KB, 4 views)
May 7 '11 #1
4 3908
ADezii
8,834 Expert 8TB
I think the problem lies in Code Line #5 whereas even if the Sub-Form has the Focus, ActiveForm will still refer to the Main Form. That being said, in Code Line #20, only Controls in the Main Form will be processed in the For...Each Loop.
Expand|Select|Wrap|Line Numbers
  1. Dim MyForm As Form
  2. Dim ctl As Control
  3. Dim sUser As String
  4.  
  5. Set MyForm = Screen.ActiveForm
  6.  
  7. 'sUser = "User: " & UsersID 'You need to identify your users if you are not using Access security with workgroups.
  8. sUser = CurrentUser
  9.  
  10. 'If new record, record it in audit trail and exit function.
  11. If MyForm.NewRecord = True Then
  12.   MyForm!AuditTrail = MyForm!tbAuditTrail & "New Record added on " & Now & " by " & sUser & ";"
  13.     Exit Function
  14. End If
  15.  
  16. 'Set date and current user if the form (current record) has been modified.
  17. MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & vbLf & "Changes made on " & Now & " by " & sUser & ";"
  18.  
  19. 'Check each data entry control for change and record old value of the control.
  20. For Each ctl In MyForm.Controls
  21.   'Only check data entry type controls.
  22.   Select Case ctl.ControlType
  23.     Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
  24.       MsgBox ctl.Name & " | " & ctl.OldValue & " | " & ctl.Value
  25.        If ctl.Name = "tbAuditTrail" Then GoTo TryNextControl 'Skip AuditTrail field.
  26.  
  27.        'If new and old value do not equal
  28.        If ctl.Value <> ctl.OldValue Then
  29.          MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & ctl.Name & ": Changed From: " & ctl.OldValue & ", To: " & ctl.Value
  30.        'If old value is Null and new value is not Null
  31.        ElseIf IsNull(ctl.OldValue) And Len(ctl.Value) > 0 Or ctl.OldValue = "" And Len(ctl.Value) > 0 Then
  32.          MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & ctl.Name & ": Was Previoulsy Null, New Value: " & ctl.Value
  33.        'If new value is Null and old value is not Null
  34.        ElseIf IsNull(ctl.Value) And Len(ctl.OldValue) > 0 Or ctl.Value = "" And Len(ctl.OldValue) > 0 Then
  35.          MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & ctl.Name & ": Changed From: " & ctl.OldValue & ", To: Null"
  36.        End If
  37. End Select
  38. 'Code intentionally omitted
May 7 '11 #2
Thanks.

will try to work around it and see if I can come up with some thing.

Raghu
May 8 '11 #3
Found the solution. All I did was to make MyForm an input parameter for the sub "Audit_Trail" making it "Audit_Trail(MyForm As Form)"

Then in the code module of each form I changed the "Call Audit_Trail" to "Audit_Trail Me"

What is happening is that when the Form_BeforeUpdate event fires the reference to the form is passed to the Audit_Trail routine by using the reserved word "Me".
May 8 '11 #4
Where did you find your sample database on this site?
Nov 11 '11 #5

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

Similar topics

6
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...
0
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...
3
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...
2
by: Zlatko Matić | last post by:
I tried to implement triggers for filling audit-trail table on this way. Everything works fine as long as I don't update the primary key field value. When I try to update PK value, an error...
3
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...
6
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...
0
by: hary08 | last post by:
I have a module copied ftom this site, here it is: Option Compare Database Option Explicit Public Function AuditTrail() On Error GoTo Err_Audit_Trail 'ACC2000: How to Create an Audit...
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...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately. Code for Audit...
6
by: babamc4 | last post by:
I have a main form (mainformlung) with 5 subforms (followupacute, followuplate, biochemresults, haemresults and pftresults). I have copied Allen Browne's Audit Trail code (thanks to Allen Browne)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.