搜索数据库中某个时间段的数据

木木木小小 2016-07-18 04:13:50
我需要做一个几个条件一起的搜索,但是只要有时间段的搜索就提示Data type mismatch in criteria expression,请问有人知道是怎么回事吗?代码如下(其中数据库里面的时间格式也设置为: "YYYY/MM/DD")

Private Sub SearchList(str)
...
rs.Open str, cnn, adOpenKeyset, adLockOptimistic
...
end sub

Private Function str()
str = "SELECT * from [NDTData] where ID>0"
If ID.Value <> "" Then
str = str & " and ID=" & ID.Value
End If
If Inspector.Value <> "" Then str = str & " and Inspector like '%" & Inspector.Value & "%'"
If PONo.Value <> "" Then str = str & " and PONo like '%" & PONo.Value & "%'"
If Wbs.Value <> "" Then str = str & " and Wbs like '%" & Wbs.Value & "%'"
If Component.Value <> "" Then str = str & " and Component like '%" & Component.Value & "%'"
If MaterialNo.Value <> "" Then str = str & " and MaterialNo like '%" & MaterialNo.Value & "%'"
If Marking.Value <> "" Then str = str & " and Marking like '%" & Marking.Value & "%'"
If DTPicker2.Value <> "1601/1/1" Then str = str & " and DIGDate between '#" & Format(DTPicker1.Value, "YYYY/MM/DD") & "#'" & "and '#" & Format(DTPicker2.Value, "YYYY/MM/DD") & "#'"
end sub
...全文
155 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
木木木小小 2016-07-19
  • 打赏
  • 举报
回复
多谢二楼,解决问题了
无·法 2016-07-18
  • 打赏
  • 举报
回复
str = str & " and DIGDate between '#" & Format(DTPicker1.Value, "YYYY/MM/DD") & "#'" & "and '#" & Format(DTPicker2.Value, "YYYY/MM/DD") & "#'"
改成:
str = str & " and DIGDate>= #" & DTPicker1.Value & "# and DIGDate<=#" & DTPicker2.Value & "# "
试试看

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧