cnn.open......
rs.open"select * from table where isnull(返回日期) and 交接日期>= dateadd("d",date(),-15)",cnn,3,3
msgbox rs.recordcount
rs.open"select * from table where isnull(返回日期) and 交接日期>= dateadd("d",date(),-15)",cnn,3,3
msgbox rs.recordcount
dim thedate as date
thedate=dateadd("d",date(),-15)",
rs.open"select * from table where isnull(返回日期) and 交接日期 between thedate and date()",cnn,3,3
msgbox rs.recordcount
开始时,我没有仔细看,原来你全用的AND运算,那么条件中只要有一个为假就不能会执行循环体。你跟踪进去,看看,你的记录集是否为空。其次,你从数据库中取出某条指定的你认为满足你设定的条件(即:能让程序执行循环体)的记录,然后你看看Select出来的,其Date是否为NULL(如果你指定的是NULL的那条记录的话),并且判断日期差。and 是与逻辑运算。在进行上面的逻辑运算是,可以简单看作相当于数学中的乘法。也就是说只要有一个条件为假,你的循环体就无法执行。上面是你调试程序时,首先测试的。如果确认条件不会有错。那么就看你的查询语句是否存在错误,这个错误数据库里并不认为是错误,也就说不是语法错误,而是逻辑错误。仔细瞧瞧吧,跟踪是必要的。
我估计是这句重视返回false
在=比较符中如果expression1 or expression2 = Null,那么这了表达是返回子就是NULL,一般来讲NULL为false
应该isnull(rs!返回日期)
date1 = rs!交接日期
t = DateDiff("d", date1, today)
i = 0
Do While Not rs.EOF and not rs.bof
if rs!返回日期 = Null And DateDiff("d", date1, today) <= 15 then
i = i + 1
end if
rs.MoveNext
Loop