"Data type mismatch in criteria expression." MS 访问错误,我已按照建议进行了所有故障排除

"Data type mismatch in criteria expression." error in ms access, i did all the troubleshooting suggested

我在查询中收到错误 "Data type mismatch in criteria expression."。

这样查询就完美了

WorkingDays([ORDER_NOTIFICATION_DATE],[OP_DISTRIBUTION_DATE]) AS
BOOKING_DAYS, IIf([BOOKING_DAYS]>8,"IS LATE","ON TIME") AS BOOKING_DELAYED
FROM JOB INNER JOIN [ORDER] ON JOB.[JOB_ID] = ORDER.[JOB_ID]
WHERE (((ORDER.ORDER_NOTIFICATION_DATE) Is Not Null) AND
((ORDER.OP_DISTRIBUTION_DATE) Is Not Null));

当我尝试输入另一个标准时,它显示错误:

WorkingDays([ORDER.ORDER_NOTIFICATION_DATE],[ORDER.OP_DISTRIBUTION_DATE]) AS 
BOOKING_DAYS, IIf([BOOKING_DAYS]>8,"IS LATE","ON TIME") AS BOOKING_DELAYED
FROM JOB INNER JOIN [ORDER] ON JOB.[JOB_ID] = ORDER.[JOB_ID]
WHERE (((ORDER.ORDER_NOTIFICATION_DATE) Is Not Null) AND 
((ORDER.OP_DISTRIBUTION_DATE) Is Not Null) AND
((WorkingDays([ORDER.ORDER_NOTIFICATION_DATE],
[ORDER.OP_DISTRIBUTION_DATE]))>8));

WorkingDays returns一个整数,我尝试了其他帖子中提出的大部分解决方案。

这是工作日:

Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name:     WorkingDays
' Inputs:   StartDate As Date
'   EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date:     February 19, 1997
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function does not account for holidays.
'....................................................................
On Error GoTo Err_WorkingDays

Dim intCount As Integer



intCount = 0
Do While StartDate <= EndDate
'Make the above < and not <= to not count the EndDate

Select Case Weekday(StartDate)
Case Is = 1, 7
intCount = intCount
Case Is = 2, 3, 4, 5, 6
intCount = intCount + 1
End Select
StartDate = StartDate + 1  
Loop
WorkingDays = intCount

Exit_WorkingDays:
Exit Function

Err_WorkingDays:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select

End Function

我看到您正在使用 Is Not Null 和一个无法在同一查询中处理 Null 值的函数。

虽然您可能认为这可以正常工作,但随着 Null 值被过滤掉,它们仍然会传递给此函数并产生错误。

使用 Nz 转义传递给函数的空值:

WorkingDays(Nz([ORDER.ORDER_NOTIFICATION_DATE], 0),Nz([ORDER.OP_DISTRIBUTION_DATE], 0)) AS 
BOOKING_DAYS, IIf([BOOKING_DAYS]>8,"IS LATE","ON TIME") AS BOOKING_DELAYED
FROM JOB INNER JOIN [ORDER] ON JOB.[JOB_ID] = ORDER.[JOB_ID]
WHERE (((ORDER.ORDER_NOTIFICATION_DATE) Is Not Null) AND 
((ORDER.OP_DISTRIBUTION_DATE) Is Not Null) AND
((WorkingDays(Nz([ORDER.ORDER_NOTIFICATION_DATE], 0),
Nz([ORDER.OP_DISTRIBUTION_DATE], 0)))>8));