我正在尝试使用Dlookup在查询中使用两个条件(" s""错误")来查找值以填充变量" SCount" 。 s是移位数的整数,Error是字符串。两者都是查询中的字段。 Dlookup从一个查询中提取,该查询应该是数据类型的字符串,查询是从字段为字符串的表中提取的。所以我不确定为什么会出现不匹配错误。
当我运行代码时,我收到错误"运行时错误' 3464'标准或表达式中的数据类型不匹配"。对于SCount Dlookup中的Error
。
代码
Dim Error As String
Dim i As Integer
Dim s As Integer
Dim n As Integer
Dim SCount As Variant
Dim sum As Double
sum = 0
i = 1
s = 1
n = 1
Do Until i > 5
If Not IsNull(DLookup("[Type of Error]", "RankedSumOfErrors", "[Ranking] = " & i)) Then
Error = DLookup("[Type of Error]", "RankedSumOfErrors", "[Ranking] = " & i)
Me.Controls("lbl" & i & "").Caption = Error
Do Until s > 3
SCount = DLookup("[SumOfNumber of Errors]", "ErrorsByShift", "[Shift] = " & s & " AND [Type of Error] = '" & Error & "'")
Me.Controls("lbls" & s & "").Caption = SCount
i = i + 1
sum = sum + SCount
Loop
Me.Controls("Total" & i & "").Caption = sum
sum = 0
Else
Me.Controls("lbl" & i & "").Caption = "N/A"
i = i + 1
End If
Loop