【问题标题】:MS Access need to cancel SendObject when query returns no records查询返回无记录时,MS Access 需要取消 SendObject
【发布时间】:2014-04-18 17:46:21
【问题描述】:

我不是非常精通或接受过代码等方面的正式教育,但我需要一些帮助,在 Access 2007 模块中工作并添加一两行以在没有返回记录时不发送电子邮件。

这几乎就是我现在正在使用的东西:

Function Random_Report()
homepath = "\\server\folder\folder2\folder3\"
strFileName = "Random_Report” & ".xls"
DoCmd.OutputTo acOutputQuery, "Random_Report", acFormatXLS, homepath & strFileName, False

DoCmd.SendObject acSendQuery, " Random_Report ", acFormatXLS, "Someone2@company.com", , , _
" Random_Report ", "Good Afternoon Someone," _
& vbNewLine & "The Random_Report is ready for review at "\\server\folder\folder2\folder3\ and is attached to this email." _
& vbNewLine & "" & vbNewLine & "Thanks," _
& vbNewLine & "" & vbNewLine & "Someone Else", False

所以无论如何它都会发送报告,但是当报告为空白时,我可以添加什么来阻止它发送电子邮件?

【问题讨论】:

    标签: sql ms-access module ms-access-2007 vba


    【解决方案1】:

    使用DCount 检查查询 (Random_Report) 是否返回任何行。并且仅当DCount 报告至少一行时才执行其他操作。

    If DCount("*", "Random_Report") > 0 Then
        ' output file and send
    End if
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多