如果我没有填写表单中的所有必填字段,当我单击右上角的“x”时会出现一个丑陋的错误。我想用自定义错误消息覆盖默认错误,但我无法确定将此代码与哪个 VBA 事件相关联。当我在其中放置错误处理程序时,Form_Close 事件似乎不起作用。
访问 2010
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Unload ' Initialize error handling.
'insert routine
Exit_Unload: ' Label to resume after error.
Exit Sub ' Exit before error handler.
Err_Unload: ' Label to jump to on error.
'MsgBox Err & " " & Error$ ' Place error handling here.
Resume Exit_Unload
End Subenter code here
即使在使用此代码时仍然收到错误。
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Unload ' Initialize error handling.
' Code to do something here.
Exit_Unload: ' Label to resume after error.
Exit Sub ' Exit before error handler.
Err_Unload: ' Label to jump to on error.
'MsgBox Err & " " & Error$ ' Place error handling here.
Resume Exit_Unload
End Sub