【问题标题】:CONDITION STATEMENT IN ACCESS REPORT访问报告中的条件声明
【发布时间】:2015-03-17 05:49:53
【问题描述】:

如何在报表访问中设置条件 if else 语句?

这是报告中搜索特定数据的编码.....

Dim lngID As String
lngID = InputBox("Enter RF No")
If lngID = "" Then
DoCmd.ClearMacroError
Else
DoCmd.OpenReport "Requisition_ReportComplete", acViewReport, , "[RF_no]=" & lngID
End If

这是 if else 语句的编码

Dim lngID As String

lngID = InputBox("Enter RF No")
If lngID = "" Then
DoCmd.ClearMacroError
ElseIf lngID <> RF_no Then
MsgBox "Data not exist"
Else
DoCmd.OpenReport "Requisition_ReportComplete", acViewReport, , "[RF_no]=" & lngID
End If

用于搜索的 if else 语句不能满足我的需求..我不知道为什么....

【问题讨论】:

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


    【解决方案1】:

    我假设 RF_no 是参考编号并且是主键。如果 RF_no 只是您在 If 语句之前定义的一个特定数字,您的代码将正常工作。在打开表单之前检查表中是否存在记录的一种方法是使用 Dcount 或 Dlookup,即:

    ElseIf DCount("SomeField", "YourTable", "RF_no=" & lngID) = 0 Then
    
    ElseIf IsNull(DLookup("[Some Field]", "YourTable", "[RF_no] = " & lngID)) Then
    

    任何一个都应该可以正常工作。他们将检查您的表中是否存在 ID = lngID 的记录,如果没有找到,则会打开表单。

    【讨论】:

    • 如果我把RF_no放在输入框的lngID中,如果记录不存在怎么办?我是否需要使用 来确定 RF_no 是否存在? @罗伯特
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多