|
3#
楼主 |
发表于 2002-4-10 05:07:00
|
只看该作者
文件二
原文及译文:
Ask before saving record
(Q) How can I control when a record is saved in a form?
(问)当窗体中的记录保存时,我怎样控制?
(A) Use the form's BeforeUpdate event to run code each time Access tries to save a record. This way, if the user doesn't want to save a record, you can issue an Undo command instead of saving the record.
(答):每一次ACCESS试图保存一个记录时,使用窗体的BeforeUpdate事件,这样,如果使用者不希望保存,可以发出Undo命令代替保存记录
Note: This will generate a Message Box asking for confirmation each time a changed record is saved. I leave it on whoever is going to follow this method to determine how to refine this per user preference. (Hint: Try a Checkbox.)
备注:下面程序将产生一个信息框要求确认每次记录改变时是否保存,(后一句不知如何翻译,大意是)我让程序在使用这种方法之后的每一位使用者确认自已的决定后(YES SAVE OR NO)再做出反应,(提示:尝试使用Checkbox)
'****************** Code Start ******************
'****************** 代码开始******************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."’数据变更
strMsg = strMsg & "@Do you wish to save the changes?"’你希望保存变更
strMsg = strMsg & "@Click Yes to Save or No to Discard changes."’单击YES保存或者单击NO忽略更改
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
‘译者按,此处可以使用ME.UNDO或者ME.控件名.UNDO,前者指窗体中的当前记录不保存,后者指当前窗体中当前控件值不保存
'For Access 95, use DoMenuItem instead
‘在ACCESS95中,使用DoMenuItem代替
'DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
End Sub
'****************** Code End ******************
'****************** 代码结束 ******************
我的英文和计算机都不好,如果有错误,请大家不吝指正 |
|