473,394 Members | 1,750 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,394 software developers and data experts.

What's wrong with my Audit Trail code?

I have this code to keep track of the changes in a form. It is suppose to tell me what was changed, when, and by whom. I have this code as a module

Expand|Select|Wrap|Line Numbers
  1. Public Function Audit_Trail()
  2. On Error GoTo Err_Audit_Trail
  3.  
  4.  
  5.     Dim MyForm As Form
  6.     Dim ctl As Control
  7.     Dim sUser As String
  8.     Set MyForm = Screen.ActiveForm
  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 " & UserName() & ";"
  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 " & UserName() & ";"
  18.  
  19.     'Check each data entry control for change and record old value of the control.
  20.     For Each ctl In MyForm.Controls
  21.  
  22.     'Only check data entry type controls.
  23.     Select Case ctl.ControlType
  24.     Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
  25.         If ctl.Name = "tbAuditTrail" Then GoTo TryNextControl 'Skip AuditTrail field.
  26.             'If new and old value do not equal
  27.             If ctl.Value <> ctl.OldValue Then
  28.                 MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & ctl.Name & ": Changed From: " & ctl.OldValue & ", To: " & ctl.Value
  29.             'If old value is Null and new value is not Null
  30.             ElseIf IsNull(ctl.OldValue) And Len(ctl.Value) > 0 Or ctl.OldValue = "" And Len(ctl.Value) > 0 Then
  31.                 MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & ctl.Name & ": Was Previoulsy Null, New Value: " & ctl.Value
  32.             'If new value is Null and old value is not Null
  33.             ElseIf IsNull(ctl.Value) And Len(ctl.OldValue) > 0 Or ctl.Value = "" And Len(ctl.OldValue) > 0 Then
  34.                 MyForm!AuditTrail = MyForm!tbAuditTrail & vbCrLf & ctl.Name & ": Changed From: " & ctl.OldValue & ", To: Null"
  35.             End If
  36.     End Select
  37.  
  38. TryNextControl:
  39.     Next ctl
  40.  
  41. Exit_Audit_Trail:
  42.     Exit Function
  43.  
  44. Err_Audit_Trail:
  45.     If Err.Number = 64535 Then 'Operation is not supported for this type of object.
  46.         Exit Function
  47.     ElseIf Err.Number = 2475 Then 'You entered an expression that requires a form to be the active window
  48.         Beep
  49.         MsgBox "A form is required to be the active window!", vbCritical, "Invalid Active Window"
  50.     Else
  51.         Beep
  52.         MsgBox Err.Number & " - " & Err.DESCRIPTION
  53.     End If
  54.     Resume Exit_Audit_Trail
  55.  
  56. End Function
and I'm calling the module in my form under before update like this:

Expand|Select|Wrap|Line Numbers
  1. On Error GoTo Form_BeforeUpdate_Err
  2.  
  3.     Call Audit_Trail
  4.  
  5. Form_BeforeUpdate_Exit:
  6.     Exit Sub
  7.  
  8. Form_BeforeUpdate_Err:
  9.     MsgBox Err.Number & " - " & Err.DESCRIPTION
  10.     Resume Form_BeforeUpdate_Exit
Right now, it tells me when the record was added and by whom but if I go back and edit the record then it does nothing.

Any ideas?

Thanks for the help!
Aug 17 '10 #1
0 1127

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

Similar topics

6
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
0
by: Michael Rogers | last post by:
I wrote a simple file transfer, but it doesn't work! When I try to open the transferred file it says: "The end of file cropped" or "the file header cropped". what's wrong with this code? IS there a...
2
by: Rui Macdonald | last post by:
What is wrong with this code to populate a DropDownList? Can somebody Help me? Tnx RMac ===================================================================================== WebForm.aspx.vb
6
by: doncee | last post by:
This is the set up: is a date field on a form. Its control source is the field "date_entered" in"Table1". If there is a date showing in the date_entered field (Text6) & the status in Combo box2...
12
by: questions? | last post by:
I am testing a problem with linked list. I just do a lot of times: create a list, then free it. ############################################# # include <stdio.h> # include <stdlib.h> struct...
18
by: Sean Zhang | last post by:
The following is the code: struct S { int i; int * p; }; void main() { Struct S s; int * p = &s.i; p = 4;
5
by: Adrian | last post by:
What is wrong in the code below? Adrian. using System; namespace ConsoleApplication2 { class Trial { static void Main(string args)
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
30
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
2
by: ccgrl451 | last post by:
Okay, so you probably haven't seen my previous question, whats wrong with this code. For those who have, you know what I'm talking about. If not, heres what I have to do. We have to do this...
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: 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
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...

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.