防止错误2501

时间:2015-04-27 17:24:57

标签: vba email ms-access

我创建了一个表单,点击命令按钮创建并发送电子邮件并发送电子邮件。但是当电子邮件页面出现并且用户退出电子邮件而不发送它时会弹出错误2501。是否有人知道如何通过弹出一个消息框来通知用户电子邮件被取消来防止此错误?

提前致谢

这是我到目前为止所做的:

On Error GoTo errhandle
Me.Filter = "CurrentDate= #" & Format(Me!CurrentDate, "yyyy\-mm\-dd") & "# and DiscoverTime= '" & Me!DiscoverTime & "' and TailNumber= '" & Me!TailNumber & "' and FleetID= '" & Me!FleetID & "'"
Me.FilterOn = True
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "Email", "", "", "Recovery Report", "Attached is the submitted Recovery Report"

DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
End If

errhandle:
If Err.Number <> 2501 Then
MsgBox ("Email Cancelled")
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
End If

1 个答案:

答案 0 :(得分:1)

你有相反的逻辑。抛出的错误是2051,因此您应该检查该错误不是&lt;&gt;。另外请使用完整的代码,这样就可以更容易地提供正确的解决方案。这是修改后的代码。

<!c07case1.html>
<HTML>
<HEAD><TITLE>Washington Middle School</TITLE></HEAD>
<BODY>
<H1>Temperature Converter</H1>
<HR>
<FORM ACTION="https://crux.baker.edu/~wmorni01/cgi-bin/chap07_wendy_morningstar/c07case1.cgi" METHOD=POST>
<P><B>Temperature:</B> <INPUT TYPE=text NAME=temp></P>

<INPUT TYPE=radio NAME=unit Value=fah CHECKED>Fahrenheit to Celsius<BR>
<INPUT TYPE=radio NAME=unit Value=cel>Celsius to Fahrenheit<BR>

<P><INPUT TYPE=submit VALUE=Convert></P>
</FORM></BODY></HTML>