Vba 检查控件是否已更新

Vba 检查控件是否已更新,vba,ms-access,Vba,Ms Access,我的目标是,如果有人对该记录进行了更改,请向该记录的创建者发送电子邮件。我通过谷歌搜索找到了if Updated(ctl),但该页面没有定义该函数的有效负载。我想我可以对每个控件执行DLookup,但这似乎需要很长时间。有没有办法快速确定控件是否已更新 Private Sub Form_AfterUpdate() On Error GoTo Form_AfterUpdate_Err Dim ctl As Control Dim updates As String For Each ctl In

我的目标是,如果有人对该记录进行了更改,请向该记录的创建者发送电子邮件。我通过谷歌搜索找到了
if Updated(ctl)
,但该页面没有定义该函数的有效负载。我想我可以对每个控件执行
DLookup
,但这似乎需要很长时间。有没有办法快速确定控件是否已更新

Private Sub Form_AfterUpdate()
On Error GoTo Form_AfterUpdate_Err
Dim ctl As Control
Dim updates As String
For Each ctl In Me.Controls
    If Updated(ctl) Then
        updates = updates & ctl.Name & " has been updated to " & ctl.value & vbCrLf
    End If
Next ctl

If Len(updates) > 0 Then
    Dim appOutlook As Outlook.Application
    Dim newEmail As Outlook.MailItem
    Dim signature As String
    Set appOutlook = CreateObject("Outlook.Application")
    Set newEmail = appOutlook.CreateItem(olMailItem)

    With newEmail
        signature = .Body
        .BodyFormat = olFormatRichText
        .To = DLookup("[email]", "[tbl_users]", "[checkNumber] = '" & Me.a10_contact_name & "'")
        .Subject = Me.a1_mva_reference
        .Body = DLookup("[firstName]", "[tbl_users]", "[checkNumber] = '" & Me.a10_contact_name & "'") & "," & vbCrLf & vbCrLf & _
            "This email is regarding " & Me.a1_mva_reference & " - " & Me.a13_description & vbCrLf & vbCrLf & _
            updates & vbCrLf & vbCrLf & _
            signature
            .Display
    End With

End If

Form_AfterUpdate_Exit:
        Exit Sub
Form_AfterUpdate_Err:
        Dialog.Box (Error$)
        Resume Form_AfterUpdate_Exit
End Sub

我已经解决了这个问题。下面对代码的修改是有效的

旧代码:

Dim ctl As Control
Dim updates As String
For Each ctl In Me.Controls
    If Updated(ctl) Then
        updates = updates & ctl.Name & " has been updated to " & ctl.value & vbCrLf
    End If
Next ctl
新代码:

If Me.Dirty Then
    Dim ctl As Control
    Dim updates As String
    Dim signature As String
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
            If ctl.value <> ctl.OldValue Then
                updates = updates & ctl.Name & " has been updated from " & ctl.OldValue & " To " & ctl.value & "<br>"
            End If
        End If
    Next ctl
如果是我,那就脏了
Dim-ctl作为对照
将更新设置为字符串
作为字符串的数字签名
对于Me.Controls中的每个ctl
如果ctl.ControlType=acTextBox或ctl.ControlType=ACCOMBOX,则
如果ctl.value ctl.OldValue,则
updates=updates&ctl.Name&“已从”&ctl.OldValue&“更新为”&ctl.value&“
” 如果结束 如果结束 下一个ctl
如果控件是数据绑定的,最好使用的事件是Form_Dirty,并结合Form_AfterUpdate。看看吧。如果你有问题,在这里告诉我。