处理NULL = Access VBA中的NULL比较

时间:2017-08-03 21:17:46

标签: ms-access access-vba

NULL = NULL返回NULL时遇到问题。我希望它返回True。经过一番研究后,我发现了一条我认为可行的线路。

set ansi_nulls off

我很快就了解到Access无法识别它。所以在这里我试图在Access中做嵌套条件,这是一场彻头彻尾的噩梦。

有没有更简单的方法来解决这个问题?

2 个答案:

答案 0 :(得分:1)

如果您正在做大量的"等于或同时为空"比较,有多种解决方案:

  1. 如果您在比较数字时使0 = Null结果为真,或者在比较字符串时结果为"" = Null,则可以使用:

    If Nz(Value1) = Nz(Value2) Then

  2. 根据输入类型,这将取代0""的所有Null。

    后果:Nz(Null) = Nz(Null)True0 = Nz(Null)True"" = Nz(Null)True1 = Nz(Null)→{{1 },False"a" = Nz(Null)

    1. 创建用户定义的函数以进行比较
    2. 功能:

      False

      使用该功能:

      Public Function CompareWithNulls(Value1 As Variant, Value2 As Variant) As Boolean If IsNull(Value1) And IsNull(Value2) Then CompareWithNulls = True Else CompareWithNulls = Value1 = Value2 End If End Function

答案 1 :(得分:0)

您可以使用If IsNull(Value1) And IsNull(Value2) Then 关键字测试多个条件而无需嵌套:

=

你可以创建一个方法来比较两个变量和一个空检查,然后每个IF只需要调用这个函数而不是通常的I/flutter (15773): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (15773): The following assertion was thrown building FutureBuilder(dirty; state: I/flutter (15773): _FutureBuilderState#fe2cf()): I/flutter (15773): setState() or markNeedsBuild() called during build. I/flutter (15773): This Overlay widget cannot be marked as needing to build because the framework is already in the I/flutter (15773): process of building widgets. A widget can be marked as needing to be built during the build phase I/flutter (15773): only if one of its ancestors is currently building. This exception is allowed because the framework I/flutter (15773): builds parent widgets before children, which means a dirty descendant will always be built. I/flutter (15773): Otherwise, the framework might not visit this widget during this build phase. I/flutter (15773): The widget on which setState() or markNeedsBuild() was called was: I/flutter (15773): Overlay([LabeledGlobalKey<OverlayState>#5da5e]; state: OverlayState#12b2d(tracking 2 tickers; I/flutter (15773): entries: [OverlayEntry#b3821(opaque: true; maintainState: false), OverlayEntry#b2a00(opaque: I/flutter (15773): false; maintainState: true), OverlayEntry#a0c04(opaque: true; maintainState: false), I/flutter (15773): OverlayEntry#11271(opaque: false; maintainState: true), OverlayEntry#54209(opaque: false; I/flutter (15773): maintainState: false), OverlayEntry#1a91b(opaque: false; maintainState: true)])) I/flutter (15773): The widget which was currently being built when the offending call was made was: I/flutter (15773): FutureBuilder(dirty; state: _FutureBuilderState#fe2cf()) I/flutter (15773):