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

Track Changes in Form with sub-form & multiple tabs

Hi,

I've made a multi user (4 end users) database in Access 2000. I've made data tables, reference tables etc which sits on a shared drive and I've made individual front ends for the end users which gives them specific views of the data.
I'd like to track all the changes made to a record which works find with the following code :
basAuditTrail:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Const cDQ As String = """"
  4. Sub AuditTrail(frm As Form, recordid As Control)
  5.   'Track changes to data.
  6.   'recordid identifies the pk field's corresponding
  7.   'control in frm, in order to id record.
  8.   Dim ctl As Control
  9.   Dim varBefore As Variant
  10.   Dim varAfter As Variant
  11.   Dim strControlName As String
  12.   Dim strSQL As String
  13.   On Error GoTo ErrHandler
  14.   'Get changed values.
  15.   For Each ctl In frm.Controls
  16.     With ctl
  17.     'Avoid labels and other controls with Value property.
  18.     If .ControlType = acTextBox Then
  19.       If .Value <> .OldValue Then
  20.         varBefore = .OldValue
  21.         varAfter = .Value
  22.         strControlName = .Name
  23.         'Build INSERT INTO statement.
  24.         strSQL = "INSERT INTO " _
  25.            & "Audit (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****nSQL strSQL
  38.         DoCmd.SetWarnings True
  39.       End If
  40.     End If
  41.     End With
  42.   Next
  43.   Set ctl = Nothing
  44.   Exit Sub
  45.  
  46. ErrHandler:
  47.   MsgBox Err.Description & vbNewLine _
  48.    & Err.Number, vbOKOnly, "Error"
  49. End Sub
I call the above mentioned procedure in a single form with :
in event procedure : Before Update:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   Call AuditTrail(Me, [Shipper ID])
  3. End Sub
Now here's the problem, the above mentioned code seems to work OK when using a single form but as soon as I add in a SubForm (in which ideally I want to track changes made too) everything comes to a halt with the mention of :
"The expression Before Update you entered as the event property setting produced the following error: A problem occurred while Microsoft Office Access was communicating with the OLE server or ActiveX Control.
* The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
* There may have been an error evaluating the function, event, or macro."

Any help on this would be GREATLY appreciated!

Thanks
Nov 12 '09 #1
3 4158
ChipR
1,287 Expert 1GB
Not enough information here, especially related to the subform. If you copied this BeforeUpdate code to the subform, it probably can't find a sub called AuditTrail because it's in another module. Side note, why is recordid a Control rather than a String?
Nov 12 '09 #2
NeoPa
32,556 Expert Mod 16PB
I suspect this problem is related to something you've done (in the form setup somewhere) that you haven't actually told us about. Easy enough to do when you don't know what the problem is of course, but look at what's set up to link the code to the form.

As a separate point (unrelated to your problem), I would bring your attention to your use of cDQ within your SQL code. This should work, but doesn't produce very portable code (and it's actually not quite correct - even though Access itself still defaults to this way of quoting. See Quotes (') and Double-Quotes (") - Where and When to use them for a fuller explanation of the issues.
Nov 15 '09 #3
Hi,
I've attached a watered-down version of the database (3 tables, 5 forms and 2 modules), as you open the database and try to update a field (in the OE_Small form) and click in the sub-form the error msg appears....
I've tried a work-a-round by using 2 modules (so that the main form and subform can call on a module each) but it didn't work either!
I'm pretty much at my wits end! Any help would be appreciated!
Thanks
Attached Files
File Type: zip Audit_Errors.zip (164.8 KB, 173 views)
Nov 16 '09 #4

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

Similar topics

3
by: LC | last post by:
hi, i worry about people doing something they shouldn't to my db and I would like to track any structural changes (who and which)to my db. I am using oracle 8.0.6.0.0 and 9.2.0.2.0. regards,...
1
by: Ezekiël | last post by:
hello, I was wondering how to track all changes on tables by using some sort of a history table. What i would like is a generic history table where i can see who updated, inserted, deleted or...
1
by: JLuppens | last post by:
Does anyone know if there is a way to track changes in a text field like word does? I am using a SQL2000 database and can use either VB.Net or Access. The field is either ntext or Varchar. I...
5
by: Colleyville Alan | last post by:
I have some data in a table structured like this: Date Cust_ID CUSIP Amount 01/31/2005 060208 02507M303 27,061.84...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
4
by: | last post by:
Is anyone aware of an elegant method to 'track' changes (additions, deletions, edits) to an online server on my web host...in this case various sub folders in the /IMAGES/ directory... The...
5
by: Daniel Walzenbach | last post by:
Hi, I need to track all changes made to an object. Consider the following class: Public Class Dog
2
by: metaperl | last post by:
I'm actually taking Microsoft's 2779 and just finished a lab where we kept track of our changes to the database. However, I'm not happy with the scripts interface because it does not tell me the...
3
by: PJ6 | last post by:
What's the best way to, in the general case, track changes to an object's public fields and properties? In a lot of applicatoins I've seen bahavior consistant with simple periodic checking from a...
20
by: John Sheppard | last post by:
Hello there, Does anyone know of a way to track changes to an SQL Server database so that I can easily run those changes at a later date? That is, I want to make schema changes, and record...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.