我正在爲我的數據庫中的表單設置審計跟蹤系統。我正在關注Susan Harkins的示例Here審計跟蹤表單
我的代碼適用於基於客戶表的我的表單客戶。這裏是我的代碼:
Const cDQ As String = """"
Sub AuditTrail(frm As Form, recordid As Control)
'Track changes to data.
'recordid identifies the pk field's corresponding
'control in frm, in order to id record.
Dim ctl As Control
Dim varBefore As Variant
Dim varAfter As Variant
Dim strControlName As String
Dim strSQL As String
On Error GoTo ErrHandler
'Get changed values.
For Each ctl In frm.Controls
With ctl
'Avoid labels and other controls with Value property.
If .ControlType = acTextBox Then
If .Value <> .OldValue Then
MsgBox "Step 1"
varBefore = .OldValue
varAfter = .Value
strControlName = .Name
'Build INSERT INTO statement.
strSQL = "INSERT INTO " _
& "Audit (EditDate, User, RecordID, SourceTable, " _
& " SourceField, BeforeValue, AfterValue) " _
& "VALUES (Now()," _
& cDQ & Environ("username") & cDQ & ", " _
& cDQ & recordid.Value & cDQ & ", " _
& cDQ & frm.RecordSource & cDQ & ", " _
& cDQ & .Name & cDQ & ", " _
& cDQ & varBefore & cDQ & ", " _
& cDQ & varAfter & cDQ & ")"
'View evaluated statement in Immediate window.
Debug.Print strSQL
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If
End If
End With
Next
Set ctl = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description & vbNewLine _
& Err.Number, vbOKOnly, "Error"
End Sub
然而,當我嘗試的形式我得到一個錯誤「操作不支持這種類型的對象」內子窗體我改變的數據。我能看到的錯誤是發生在這裏:
If .Value <> .OldValue Then
我的子窗體基於斷這是基於關閉三個表
我想改變下客戶產品顧客的價格查詢並保存這些更改的日誌。有什麼我失蹤或工作。
謝謝你的幫助!
這似乎是一樣http://support.microsoft.com/kb/197592,你可能看http://allenbrowne.com/appaudit.html – Fionnuala
什麼我不知道是爲什麼它在這行錯誤:如果.Value <> .OldValue然後;我該如何解決它。 –
具有多個關係的表不支持.OldValue嗎? –