我尝试过使用DCOUNT和SQL,但没有任何工作。我在下面粘贴了两个查询。当我运行SQL时,列表框中没有任何内容。当我运行DLOOKUP时,我收到错误消息“运行时错误'2001”:您取消了以前的操作。组合框名称是ScrubbedList。表名为Scrubbed。
DCOUNT
Dim strScrubbedValue As String
strScrubbedValue = Me.ScrubbedList
Dim intCountNull As Integer
intCountNull = DCount("*", "Scrubbed", "IsNull" & strScrubbedValue)
Text267 = intCountNull
SQL
Dim strSQL As String
Dim strScrubbedValue As String
strScrubbedValue = Me.ScrubbedList
strSQL = "SELECT Count(*) As CountAll" & strScrubbedValue & " FROM Scrubbed"
strSQL = strSQL + "WHERE" & strScrubbedValue = ""
Me.List265.RowSource = strSQL
答案 0 :(得分:0)
尝试:
intCountNull = DCount("*", "Scrubbed", "SomeField Is Null")
所以对于组合:
intCountNull = DCount("*", "Scrubbed", strScrubbedValue & " Is Null")
确保在连接字符串时包含相关空格非常重要。
Dim strSQL As String
Dim strScrubbedValue As String
strScrubbedValue = Me.ScrubbedList
strSQL = "SELECT Count(*) As CountAll " & strScrubbedValue & " FROM Scrubbed"
strSQL = strSQL & " WHERE " & strScrubbedValue & " Is Null"
Me.List265.RowSource = strSQL
请注意,Null和零长度字符串(ZLS)不相同。
为了得到这两者,你可以说:
strSQL = strSQL & " WHERE " & strScrubbedValue & " & '' = ''"
VBA中的字符串连接符是&而不是+。必须小心使用加号,因为它可能导致意外的空值。