vba ms access - 基于文本框值的复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10922853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ms access - checkbox based on value of textbox
提问by talbright
I am building a report in access 2007, and trying to set a checkbox to true based on the value of a string in a textbox. For example: If txtBoxValue = "Injury" then chkBoxValue = True(Checked) Else chkBoxValue = False(unchecked).
我正在访问 2007 中构建报告,并尝试根据文本框中字符串的值将复选框设置为 true。例如:如果 txtBoxValue = "Injury" then chkBoxValue = True(Checked) Else chkBoxValue = False(unchecked)。
This is the value I have in the source control of chkBoxValue.
这是我在 chkBoxValue 的源代码管理中拥有的值。
=IIf([txtBoxValue]=”Injury”,1,0)
I am new to VBA, and any help would be appreciated.
我是 VBA 的新手,任何帮助将不胜感激。
回答by HansUp
This should work as the control source of chkBoxValue
:
这应该作为 的控制源chkBoxValue
:
=([txtBoxValue]="Injury")
Be careful about the quotes you use in VBA code. Notice you used ” (ASCII 148) and I used " (ASCII 34).
请注意您在 VBA 代码中使用的引号。请注意,您使用了“(ASCII 148),而我使用了“(ASCII 34)。
Edit: As @nicholas pointed out, that control source expression will give you Null when [txtBoxValue]
is Null. If you prefer False
instead, add the Nz()
function.
编辑:正如@nicholas 指出的那样,当[txtBoxValue]
为 Null时,该控件源表达式将为您提供Null。如果您愿意False
,请添加该Nz()
功能。
=(Nz([txtBoxValue],"")="Injury")
回答by nicholas
True / False fields use values -1 and 0 in Access. You also have constants TRUE and FALSE.
真/假字段在 Access 中使用值 -1 和 0。您还有常量 TRUE 和 FALSE。
The control source of the checkbox should read:
复选框的控件源应为:
=IIf([txtBoxValue]="Injury",TRUE,FALSE)