注册 登录
编程论坛 VB6论坛

求助:多条件

新手VB 发布于 2016-02-13 20:58, 1748 次点击
"select 单号,操作日期,建单人 from 数据库  where 建单人='" & Text1.Text & "' and 单号='" & Combo1.Text & "' and 操作日期>=#" & DTPicker1.Value & "# and 操作日期<=#" & DTPicker2.Value & "# "
请问如何修改可以满足 建单人 为空就执行单号和操作日期的条件,建单人、单号 为空就执行 操作日期的条件,意思就是条件为空就忽略。
5 回复
#2
Artless2016-02-14 00:18
if text1.text=““then
"select 单号,操作日期,建单人 from 数据库  where 单号='" & Combo1.Text & "' and 操作日期>=#" & DTPicker1.Value & "# and 操作日期<=#" & DTPicker2.Value & "# "
#3
风吹过b2016-02-14 09:05
s=""
if len(text1.text)>0 then
   s=s & "and 建单人='" & Text1.Text & "' "
end if
if len(Combo1.Text)>0 then
   s=s & "and 单号='" & Combo1.Text & "' "
end if
s=mid(s,4)
s="select 单号,操作日期,建单人 from 数据库  where " & s & " and 操作日期>=#" & DTPicker1.Value & "# and 操作日期<=#" & DTPicker2.Value & "# ;"

#4
新手VB2016-02-14 12:39
回复 2楼 Artless
谢谢!
#5
新手VB2016-02-14 12:39
回复 3楼 风吹过b
谢谢!我测试下。
#6
新手VB2016-02-15 07:39
回复 3楼 风吹过b
感谢版主,测试成功了。
1