我的VBA中有以下DCount代码:
If DCount("*", "tbl2Employee_Order", _
"[Operation_Date] = #" & Operation_Date & _
"# AND [Employee_ID]= " & Employee_ID & _
" AND [Order_ID] = " & Order_ID & _
" AND [Model_Operation_ID] = " & MO_ID) = 0 Then
'some code to insert into tbl2Employee_Order
Else
'some code to update the existing record
End If但是,我的DCount总是返回0,即使记录已经存在。以下内容:
Debug.Print Operation_Date, Employee_ID, Order_ID, MO_ID, DCount("*", "tbl2Employee_Order", "[Operation_Date] = #" & Operation_Date & "# AND [Employee_ID]= " & Employee_ID & " AND [Order_ID] = " & Order_ID & " AND [Model_Operation_ID] = " & MO_ID)返回期望值,例如:
08/05/2015 2 526 1107 0 除了最后一个,它应该是1(记录已经存在)。
tbl2EmployeeOrder有这样的记录:
Operation_Date: 08/05/2015
Employee_ID: 2
Order_ID: 526
Model_Operation_ID = 1107有趣的是,几周前它还可以正常工作,突然它就表现得好像记录并不存在一样。
编辑:
以下内容:
Debug.Print TypeName(Operation_Date), TypeName(Employee_ID), TypeName(Order_ID), TypeName(MO_ID)结果如下:
Date Integer Integer Integer这些也是tbl2Employee_Order中的变量类型。
类似地,如果我使用DLookup (带有一些列名)而不是DCount,我会得到一个返回的Null值。
发布于 2015-05-26 04:20:49
您是否更改了区域设置?怎么样
If DCount("*", "tbl2Employee_Order", _
"[Operation_Date] = #" & Format(Operation_Date,"mm/dd/yyyy") & _
"# AND [Employee_ID]= " & Employee_ID & _
" AND [Order_ID] = " & Order_ID & _
" AND [Model_Operation_ID] = " & MO_ID) = 0 Then删除日期条件以查看其是否有效
https://stackoverflow.com/questions/30445264
复制相似问题