.oldValue控件属性上的错误3251 [英] Error 3251 on .oldValue control property
问题描述
我目前正在努力将审核跟踪添加到MS-Access 2010数据库中,而我却在为此而苦苦挣扎
I am currently working on adding an audit trail to a MS-Access 2010 database and I am struggling with
错误3251:此类型对象不支持操作"
"error 3251 : operation is not supported for this type object"
这是我的审计跟踪模块的代码,大部分是来自网络的编排代码:
Here is the code of my audit trail module, mostly arranged code coming from web :
Public Function auditChanges(RecordID As String, userAction As String, cForm As Form)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim ctl As Control
Dim userLogin As String
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM T_AUDIT")
userLogin = getCurrentUser
Select Case userAction
Case "New"
With rst
.AddNew
![Date] = Now()
![utilisateur] = userLogin
![nomFormulaire] = cForm.Name
![Action] = userAction
![RecordID] = cForm.Controls(RecordID).Value
.Update
End With
Case "Delete"
With rst
.AddNew
![Date] = Now()
![utilisateur] = userLogin
![nomFormulaire] = cForm.Name
![Action] = userAction
![RecordID] = cForm.Controls(RecordID).Value
.Update
End With
Case "Edit"
For Each ctl In cForm.Controls
If (ctl.ControlType = acTextBox) Or (ctl.ControlType = acComboBox) Or (ctl.ControlType = acCheckBox) Then
If (Nz(ctl.Value, "") <> Nz(ctl.OldValue, "")) Then
With rst
.AddNew
![Date] = Now()
![utilisateur] = userLogin
![nomFormulaire] = cForm.Name
![Action] = userAction
![RecordID] = cForm.Controls(RecordID).Value
![champs] = ctl.ControlSource
![ancienneValeur] = ctl.OldValue
![nouvelleValeur] = ctl.Value
.Update
End With
End If
End If
Next ctl
End Select
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
End Function
此函数在我要跟踪的表单的beforeUpdate
事件中调用.
This function is called in beforeUpdate
event of the forms I want to track.
当我尝试编辑绑定的文本框时,会引发错误.而
If (Nz(ctl.Value, "") <> Nz(ctl.OldValue, "")) Then
行是引发错误的行
The error is fired when I try to edit a bound textbox. And the line
If (Nz(ctl.Value, "") <> Nz(ctl.OldValue, "")) Then
is the line provoking the error
该表单基于2个表,这些表链接了一对多关系.当我从关系的一个"部分开始编辑表中的字段时,该功能有效,但是当我要从许多"侧编辑字段时,它将引发错误.
The form is based on 2 tables linked with a One-To-Many relationship. The function is working when I edit fields from the table which are sided to the "One" part of the relationship but it throws the error when I want to edit fields from the "Many" side.
我希望我足够清楚,谢谢
I hope I am clear enough, thank you
更多详细信息
我的表单基于该请求:
SELECT T_REVISION.ID_revision, T_REVISION.fk_ID_proposition, T_REVISION.numero, T_REVISION.fk_etat_revision, T_REVISION.EOTP, T_PROPOSITION.reference_simple, T_PROPOSITION.libelle, T_REVISION.description_localisation
FROM T_PROPOSITION INNER JOIN T_REVISION ON T_PROPOSITION.ID_proposition = T_REVISION.fk_ID_proposition
ORDER BY T_REVISION.numero DESC;
从T_PROPOSITION.reference_simple
控件引发了错误.
错误3251发生:当我尝试编辑 T_REVISION.EOTP , T_REVISION.description_localisation 字段时.当我编辑 T_PROPOSITION.reference_simple , T_PROPOSITION.libelle 时,不会发生错误3251 !
The error is fired from T_PROPOSITION.reference_simple
control.
The error 3251 occurs when : I try to edit T_REVISION.EOTP, T_REVISION.description_localisation fields. The error 3251 does not occur when I edit T_PROPOSITION.reference_simple, T_PROPOSITION.libelle !
所以:我能够编辑来自关系一侧"的值,但是当我想编辑很多"侧时,似乎无法访问oldValue属性
我该如何解决?
推荐答案
不完全是答案,但是注释区域不适合...
Not exactly an answer, but the comment area is not suitable...
如果要在If (Nz(ctl.Value, "") <> Nz(ctl.OldValue, "")) Then
之前添加2行:
If would add 2 lines BEFORE the If (Nz(ctl.Value, "") <> Nz(ctl.OldValue, "")) Then
:
debug.print ctl.Name, ctl.value
debug.print ctl.name, ctl.oldvalue
这将使您查看错误是否链接到特定控件和特定属性,并缩小搜索范围.
This will allow you to see if the error is linked to a specific control and to a specific property, and narrow your search.
编辑:编辑OP表示该问题出现在加入的许多"方面之后,我认为您应该将表单更改为.这将使您能够正确跟踪对每个TABLE的更新.
Edit: After you edited your OP indicating that the issue arises on the "many" side of you join, I think you should change your form to a "main form - subform" architecture. This will allow you to track updates to each TABLE correctly.
这篇关于.oldValue控件属性上的错误3251的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!