2427您输入了没有值的表达式 [英] 2427 You entered an expression that has no value

查看:125
本文介绍了2427您输入了没有值的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能可以根据字段id将报告分成单独的PDF文件:

I have a function to split up my report into separate PDF files based on a field id:

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

但是,在运行时,我会收到此错误/警告:

However, while running, I would get this error/warning:

2427您输入的表达式没有任何值.

2427 You entered an expression that has no value.

id为空时,会发生这种情况.我什至不知道这是一个错误还是警告.单击确定后,该函数将继续运行直到最后没有任何问题,并且输出文件将命名为N.pdf.

This happens when the id is null. I don't even know if this is an error or a warning. After I click Ok, the function continue to runs till the end without any problem, and the output file would be named N.pdf.

由于此消息框与通常的错误消息框不同,并且由于它没有给我调试或结束执行的选项,所以我想这不是错误吗?

Since this message box is not like the usual error message box, and since it doesn't give me the option to debug or end the execution, I guess it is not an error?

我尝试使用DoCmd.SetWarnings False禁止显示警告,但它不起作用.

I have tried to suppress warning using DoCmd.SetWarnings False but it doesn't work.

我该如何解决或至少抑制它以使其不显示?

How can I fix this or at least suppress it so that it doesn't show up?

推荐答案

VBA中没有短路,因此请尝试更改此方法:

There's no short-circuiting in VBA, so try changing this:

    If Not IsEmpty(rs!id) And Not IsNull(rs!id) Then
        myId = rs!id
    Else
        myId = ""
    End If

对此:

If Not rs!Id Is Nothing Then
    If Not IsNull(rs!id) Then
        If Not IsEmpty(rs!id) Then
            myId = rs!id
        Else
            myId = ""
        End If
    Else
        myId = ""
    End If
Else
    myId = ""
End IF

这篇关于2427您输入了没有值的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆