ACCESS VBA:运行时错误94无效使用null 私有函数getTMD(StartDate、EndDate、StartHour、EndHour)为双精度 Dim将md设置为整数 Md=0 diffDate=(EndDate-StartDate)-1 如果diffDate>=1,则 TENTMD=diffDate*(1080) 如果时间值(StartHour)>时间值(“06:00:00”),则 TENTEMD=TENTEMD+DateDiff(“n”,时间值(StartHour),时间值(“23:59:59”)+1 Debug.Print.md 其他的 TENTEMD=1080+TENTEMD 如果结束 如果(时间值(EndHour)>时间值(“06:00:00”)和时间值(EndHour)时间值(“23:59:00”)),则 expndtw-1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1 ElseIf TimeValue(EndHour)=TimeValue(“23:59:00”),然后 TENTMD=TENTMD+1079 如果结束 ElseIf diffDate=0,则 如果时间值(StartHour)>时间值(“06:00:00”),则 TENTEMD=DateDiff(“n”,时间值(StartHour),时间值(“23:59:59”)+1+TENTEMD 其他的 TENTEMD=DateDiff(“n”,TimeValue(“06:00:00”),TimeValue(“23:59:59”))+1+TENTEMD 如果结束 如果时间值(EndHour)>时间值(“06:00:00”)和时间值(EndHour)时间值(“23:59”),则 expndtw-1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1 ElseIf TimeValue(EndHour)=TimeValue(“23:59:00”),然后 TENTMD=TENTMD+1079 如果结束 ElseIf diffDate=-1那么 如果时间值(EndHour)>时间值(“06:00:00”)和时间值(StartHour)>时间值(“06:00:00”),则 TETTEMD=DATEFDIFF(“n”,时间值(起始小时),时间值(结束小时)) 如果时间值(EndHour)>时间值(“06:00:00”)和时间值(StartHour)时间值(“06:00:00”)和时间值(EndHour)时间值(“23:59:00”)),则 expndtw-1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1
我试图使用NZ函数,但仍然存在错误。您能帮我解决它吗?首先,如果您将空值传递给函数,就会出现这种情况 为避免此情况,请将其声明为日期: 如果值可以为Null,则使用Nz确定要替换的值,例如:ACCESS VBA:运行时错误94无效使用null 私有函数getTMD(StartDate、EndDate、StartHour、EndHour)为双精度 Dim将md设置为整数 Md=0 diffDate=(EndDate-StartDate)-1 如果diffDate>=1,则 TENTMD=diffDate*(1080) 如果时间值(StartHour)>时间值(“06:00:00”),则 TENTEMD=TENTEMD+DateDiff(“n”,时间值(StartHour),时间值(“23:59:59”)+1 Debug.Print.md 其他的 TENTEMD=1080+TENTEMD 如果结束 如果(时间值(EndHour)>时间值(“06:00:00”)和时间值(EndHour)时间值(“23:59:00”)),则 expndtw-1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1 ElseIf TimeValue(EndHour)=TimeValue(“23:59:00”),然后 TENTMD=TENTMD+1079 如果结束 ElseIf diffDate=0,则 如果时间值(StartHour)>时间值(“06:00:00”),则 TENTEMD=DateDiff(“n”,时间值(StartHour),时间值(“23:59:59”)+1+TENTEMD 其他的 TENTEMD=DateDiff(“n”,TimeValue(“06:00:00”),TimeValue(“23:59:59”))+1+TENTEMD 如果结束 如果时间值(EndHour)>时间值(“06:00:00”)和时间值(EndHour)时间值(“23:59”),则 expndtw-1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1 ElseIf TimeValue(EndHour)=TimeValue(“23:59:00”),然后 TENTMD=TENTMD+1079 如果结束 ElseIf diffDate=-1那么 如果时间值(EndHour)>时间值(“06:00:00”)和时间值(StartHour)>时间值(“06:00:00”),则 TETTEMD=DATEFDIFF(“n”,时间值(起始小时),时间值(结束小时)) 如果时间值(EndHour)>时间值(“06:00:00”)和时间值(StartHour)时间值(“06:00:00”)和时间值(EndHour)时间值(“23:59:00”)),则 expndtw-1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1\cf1,vba,ms-access,Vba,Ms Access,我试图使用NZ函数,但仍然存在错误。您能帮我解决它吗?首先,如果您将空值传递给函数,就会出现这种情况 为避免此情况,请将其声明为日期: 如果值可以为Null,则使用Nz确定要替换的值,例如: Private Function getTMD(StartDate As Date, EndDate As Date, StartHour As Date, EndHour As Date) As Double 其次,你所做的似乎过于复杂,可能是因为使用了幻数。如果您试图用通俗易懂的英语解释函数的作用,可
Private Function getTMD(StartDate As Date, EndDate As Date, StartHour As Date, EndHour As Date) As Double
其次,你所做的似乎过于复杂,可能是因为使用了幻数。如果您试图用通俗易懂的英语解释函数的作用,可能会大大减少。您到底是如何使用Nz()-Nz(EndHour,0)的?谢谢,在这个函数中,它会查看最新的文件,如果它们不在同一个月,它应该分为两个记录,例如,从2020年6月30日下午5:35到2020年7月2日下午14:25,应记录在两个记录中,即从2020年6月30日下午5:35到2020年6月30日下午23:59和从2020年7月2日上午12:00到2020年7月2日下午14:25。这只是故事的一部分。负数从何而来?我猜EndDate不能早于StartDate。06:00和1080是怎么回事?在你的例子中,为什么2020-07-01被忽略?
If (TimeValue(EndHour) > TimeValue("06:00:00") And TimeValue(EndHour) <> TimeValue("23:59:00")) Then
tempTMD = DateDiff("n", TimeValue("06:00:00"), TimeValue(EndHour)) + tempTMD
Private Function getTMD(StartDate As Date, EndDate As Date, StartHour As Date, EndHour As Date) As Double
Value = getTMD(Nz(StartDate, #00:00#), Nz(EndDate, #00:00#), Nz(StartHour, #00:00#), Nz(EndHour, #00:00#))