【发布时间】:2014-06-07 12:38:45
【问题描述】:
我已将 VBA 放入 ms access 2010 中的 Unload Form Event 中
Private Sub Form_Unload(Cancel As Integer)
Dim strMsg As String
Dim iResponse As Integer
' Specify the message to display.
strMsg = "Do you wish to save the changes?" & Chr(10)
strMsg = strMsg & "Click Yes to Save or No to Discard changes."
' Display the message box.
iResponse = MsgBox(strMsg, vbQuestion + vbYesNoCancel, "Save Record?")
' Check the user's response.
If iResponse = vbYes Then
' Undo the change.
DoCmd.RunCommand acCmdSave
End If
If iResponse = vbNo Then
' Undo the change.
DoCmd.RunCommand acCmdUndo
End If
If iResponse = vbCancel Then
' Undo the change
Cancel = True
End If
End Sub
如果数据被更改,那么上面的代码工作正常,然后是保存和关闭,否撤消和关闭并取消取消事件并保留在表单上 但是当数据不变时,是按钮工作正常,但否按钮不关闭表单
我在哪里弄错了?
【问题讨论】:
-
在调试器中单步执行。
-
问题应该在funcion
acCmdUndo尝试调试它。 -
如果没有任何变化,那么根本没有理由提示用户。只需在您的第一条语句之前添加:If Not Me.Dirty Then Exit Sub End If
-
但是当使用 me.dirty 时下面的代码不起作用
标签: ms-access vba ms-access-2007 ms-access-2010