如果......那么涉及复选框的语句 [英] If..then statement involving checkboxes
问题描述
在Access 2003中:包含四个是/否字段的表是用作报表数据源的查询的一部分。是/否字段在数据表和报告中显示为复选框;该字段的默认值为no。该报告引入了一个子报告。我希望子报表仅在任何yes / no字段包含yes时显示(在复选框中显示为复选框)。我尝试了这样的if语句:
如果Field1 =no AND Field2 =no AND Field 3 =no AND字段4 =否然后
[子报告] .visible = false
其他[子报告] .visible = true
Endif
我也尝试过使用IsNull [Field1] AND等的类似声明。
自2002年以来我没有使用Access VBA使用Access 2000 - 我迷路了。应该如何如果部分说明?
In Access 2003: A table with four yes/no fields is part of a query used as data source for a report. The yes/no fields show in the datasheet and the report as checkboxes; the default value of the field is "no". The report pulls in a subreport. I want the subreport to be visible ONLY if any of the yes/no fields contain a yes (showing as a check in the checkbox). I tried an if then statement like this:
If Field1 ="no" AND Field2 = "no" AND Field 3 = "no" AND Field 4 = "no" then
[Subreport].visible = false
Else [Subreport].visible=true
Endif
I also tried a similar statement using IsNull [Field1] AND etc.
I haven''t used Access VBA since 2002 using Access 2000 - I''m lost. How should the "if" part be stated?
推荐答案
只有当所有字段都设置为No / False时,您的语句才会起作用。
你需要什么要做的是用OR替换你的AND',并将条件设置为True。
然后如果任何字段为''Yes'',它将显示该记录。此外,布尔值不会包含引号..这些仅用于String值。
Your statement is only going to work if ALL the fields are set to No/False.
What you need to do is replace your AND''s with OR''s, and set the condition to True.
Then if any of the fields are ''Yes'', it will show that record. Also, boolean values do not get wrapped with quotes.. those are only for String values.
这是输入的代码:
Private Sub Report_Open(取消为整数)
如果COA_Required = True或Officer_Required = True或Designated_Eng_in_Resp_Charge_Required = True或Local_Office_Designated_Engineer_Required = True则
[限定符] .Visible = True
Else
[限定符] .Visible = False
结束如果
End Sub
子报表不可见。如果我翻转[Qualifiers] .Visible到
Private Sub Report_Open(取消为整数)
如果COA_Required = True或Officer_Required = True或Designated_Eng_in_Resp_Charge_Required = True或者Local_Office_Designated_Engineer_Required = True然后
[限定符] .Visible = False
Else
[限定符] .Visible = True
结束如果
结束子
子报表在所有实例中都可见,即使所有四个字段都是空的。
Here''s the code as entered:
Private Sub Report_Open(Cancel As Integer)
If COA_Required = True Or Officer_Required = True Or Designated_Eng_in_Resp_Charge_Required = True Or Local_Office_Designated_Engineer_Required = True Then
[Qualifiers].Visible = True
Else
[Qualifiers].Visible = False
End If
End Sub
The subreport is not visible. If I flip the [Qualifiers].Visible to
Private Sub Report_Open(Cancel As Integer)
If COA_Required = True Or Officer_Required = True Or Designated_Eng_in_Resp_Charge_Required = True Or Local_Office_Designated_Engineer_Required = True Then
[Qualifiers].Visible = False
Else
[Qualifiers].Visible = True
End If
End Sub
the subreport is visible in all instances, even if all four fields are empty.
你第一次实际上几乎是正确的。
你问的是你用过的没有 instread of false
You actually had it almost correct the first time.
Your problem was you used "no" instread of false
这篇关于如果......那么涉及复选框的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!