【发布时间】:2021-10-14 13:03:00
【问题描述】:
我有一个功能可以根据 id 字段将我的报告拆分为单独的 PDF 文件:
Public Function PrintList() As String
Dim MyPath As String
Dim MyFilename As String
Dim myId As String
Dim filter As String
MyPath = "C:\reports\"
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT id FROM table")
'Loop through the set
Do While Not rs.EOF
If Not IsEmpty(rs!id) And Not IsNull(rs!id) Then
myId = rs!id
Else
myId = ""
End If
filter = "id = '" & myId & "'"
'Open report preview and auto-save it as a PDF
DoCmd.OpenReport "myReport", acViewPreview, , filter
MyFilename = "N" & myId & ".pdf"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath & MyFilename, False
'Close the previewed report
DoCmd.Close acReport, "myReport"
rs.MoveNext
Loop
End Function
但是,在运行时,我会收到此错误/警告:
2427 您输入的表达式没有值。
当id 为空时会发生这种情况。我什至不知道这是错误还是警告。单击确定后,该函数继续运行到最后没有任何问题,输出文件将命名为N.pdf。
由于这个消息框不像通常的错误消息框,而且它没有给我调试或结束执行的选项,我猜这不是错误?
我曾尝试使用 DoCmd.SetWarnings False 抑制警告,但它不起作用。
我该如何解决这个问题,或者至少抑制它以使其不显示?
【问题讨论】: