我有类似的情况,我在父窗体上使用了隐藏文本控件,当任何子窗体更新时,它们会更改隐藏文本控件中的文本。然后,当用户尝试保存或退出父窗体时,我检查隐藏控件,如果它显示进行了更新,它会打开我的弹出窗体以记录所做的更改;即您的备注、姓名首字母和备注日期。
如果仅在父窗体控件上而不是在子窗体中进行更改,则父窗体上的正常窗体 BeforeUpdate 过程会捕获更改并允许您提示用户输入所需的注释。
HTH。
下面添加了更多详细信息
我的表单是订单表单,我正在跟踪已向客户确认的订单的更改。
在主窗体上,我有一个名为 txtRevToDo 的未绑定文本控件。它不可见并且没有默认值。子表单是连续表单,因此在子表单上的项目之间移动会触发更新后代码。
在更新后的子表单中,在每个单独的子表单上,我都有以下代码。我只捕获对更改的订单行有成本的订单的更新。如果没有成本,我不需要跟踪变化 -
'set the parent form to dirty so that the changes to contract items can be tracked as a revision to the contract
If Not IsNull(Me.Cost) Then
Me.Parent.txtRevToDo = "Yes"
End If
在主窗体上,用户单击“关闭”按钮退出窗体。在该按钮控件的 OnClick 事件的 vba 代码中,我使用此代码检查 txtRevToDo,如果对子窗体进行了任何可跟踪的更改,它会检查状态并将主窗体设置为脏,然后强制保存触发主窗体 BeforeUpdate 代码 -
If Me.txtRevToDo = "Yes" Then
Me.txtPaymentTerms.SetFocus
Me.Dirty = True
If Me.Dirty Then Me.Dirty = False
Else
DoCmd.Close acForm, "Edit Contract Details After Issued"
End If
触发的主窗体BeforeUpdate中的代码是这样的,该代码允许用户完成保存或返回并进行进一步的更改 -
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Are you ready to save these changes and create the Contract revision? If you have further changes to make, please select 'No'." _
, vbYesNo, "Changes Made...") = vbYes Then
'increase the revision number by 1
Me.Revision = (Me.Revision + 1)
Me.txtContractStatus = "Revised"
'update the Contract Actions table with a record of the action
strSQLApprove = ....my sql to update my table
'update this flag to reflect that the contract revision has been captured
Me.txtRevToDo = ""
'record the revision reason (this opens my pop up form that captures the changes made)
DoCmd.OpenForm "Edit Contract Revisions"
Forms![Edit Contract Revisions]!ContractNo = Me.ContractNo
Forms![Edit Contract Revisions]!txtRevision = Me.Revision
Forms![Edit Contract Revisions]!RevisedBy = TempVars!EmpID
Else
'update this flag so the revision can be captured even if no further changes are actually made
Me.txtRevToDo = "Yes"
End If
如果您需要更多详细信息,请告诉我,我希望这可以帮助您针对您的情况解决类似问题。