检查控件是否已更新



如果有人对该记录进行了更改,我的目标是向记录的创建者发送电子邮件。我通过谷歌搜索找到了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

最新更新