尝试运行查找时,我一直遇到数据类型不匹配的问题。我有一个表tWorkOrder并且有一个短文本列salesOrderNo Number列workOrderNo和Short Text lineKey我在查找中搜索lineKey值。
Dim lineKeyOW, SoNo, WTSo As String
SoNo = 0135487
WTSo = 2
lineKeyOW = Nz(DLookup("lineKey", "tWorkOrder", "salesOrderNo = '" & soNo & "' AND workOrderNo = '" & WTSo & "'"), "NA")
答案 0 :(得分:2)
喜欢这样会更好
Dim lineKeyOW As String
Dim SoNo as String
Dim WTSo As Long
SoNo = 0135487
WTSo = 2
lineKeyOW = Nz(DLookup("lineKey", "tWorkOrder", "salesOrderNo = '" & soNo & "' AND workOrderNo = " & WTSo ), "NA")
首先,workOrderNo
列为数字数据类型,您不应该使用'
然后,永远不要这样做:
Dim lineKeyOW, SoNo, WTSo As String
因为它等同于
Dim lineKeyOW As Variant, SoNo As Variant, WTSo As String
出于以下几个原因,这是完全错误的。
如果你真的想要一个内联 dim
声明,你应该这样做
Dim lineKeyOW As String, SoNo As String, WTSo As String