首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >审计跟踪代码未获取组合框列表更改

审计跟踪代码未获取组合框列表更改
EN

Stack Overflow用户
提问于 2017-08-18 03:45:11
回答 1查看 398关注 0票数 1

我看过这篇文章:Saving changes to a multivalued ComboBox via AuditTrail

并试图将花边新闻放入我的代码中,但它就是不起作用!我真的不是很擅长SQL,但我需要完成这项工作。这是我的代码,它适用于文本框,但有人能告诉我,我的combobox下拉列表更改需要放在哪里和确切的位置吗?

提前感谢!!

代码语言:javascript
复制
Function LogChanges(lngID As Long, Optional strField As String = "")
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim varOld As Variant
    Dim varNew As Variant
    Dim strFormName As String
    Dim strControlName As String


    varOld = Screen.ActiveControl.OldValue
    varNew = Screen.ActiveControl.Value
    strFormName = Screen.ActiveForm.NAME
    strControlName = Screen.ActiveControl.NAME
    Set dbs = CurrentDb()
    Set rst = dbs.TableDefs("ztblDataChanges").OpenRecordset

    With rst
        .AddNew
        !FormName = strFormName
        !ControlName = strControlName
        If strField = "" Then
            !FieldName = strControlName
        Else
            !FieldName = strField
        End If
        !RecordID = lngID
        !UserName = Environ("username")
        If Not IsNull(varOld) Then
            !OldValue = CStr(varOld)
        End If
        !NewValue = CStr(varNew)
        .Update
    End With
    'clean up
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing
End Function
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-21 17:34:41

不能使用.Value.OldValue获取多值字段的值。这些属性始终返回Null。据我所知,没有可靠的方法来获取旧值(而且,正确的审计跟踪不需要旧值,因为如果所有内容都经过适当审计,旧值就是之前添加的新值)。

如果仅保存新值,并且要将其保存到文本字段而不是多值字段中,则可以使用以下方法:

使用此函数可获取所有选定项的字符串值:

代码语言:javascript
复制
Public Function JoinMVF(MVFControl As Control, Optional Delimiter As String) As String
    Dim i As Variant
    For Each i In MVFControl.ItemsSelected
        JoinMVF = JoinMVF & MVFControl.ItemData(i) & Delimiter
    Next i
End Function

然后,将您的记录集片段调整为以下内容:

代码语言:javascript
复制
With rst
    .AddNew
    !FormName = strFormName
    !ControlName = strControlName
    If strField = "" Then
        !FieldName = strControlName
    Else
        !FieldName = strField
    End If
    !RecordID = lngID
    !UserName = Environ("username")
    If Not IsNull(varOld) Then 'varOld will always be Null for a multi-valued field
        !OldValue = CStr(varOld) 'Thus this will never get called
    End If
    'Add some If multivalued field then
    !NewValue = JoinMVF(Screen.ActiveControl, "; ")
    .Update
End With
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45743788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档