在VBA的For循环中使用DCount(Microsoft Access)

时间:2015-07-21 11:49:10

标签: vba ms-access dcount

我在VBA中遇到DCount问题。

我试图用Dcount计算的值填充数组。我在Dcount中使用的标准之一是我想要从不同的数组中获取,这就产生了问题:

Dim i As Integer
For i = 0 To (intNumberOfSplitterboxes - 1)
    Dim arrFreeSingleModePorts(243) As Variant
    arrFreeSingleModePorts(i) = 
        DCount("ID", "SplitterboxPorts", _
        "SplitterboxID=i AND Mode='SingleMode' AND IsNull(DevicePortID) AND IsNull(SplitterboxPortID)")
Next

我收到错误2471

1 个答案:

答案 0 :(得分:0)

您已在字符串中包含了i变量。要在字符串中使用i的实际值,您需要将它们连接在一起,如下所示:"SplitterboxID=" & i & " AND Mode='SingleMode' AND IsNull(DevicePortID) AND IsNull(SplitterboxPortID)"