'再说一点,如果条件可选可不选,则可用" where 1=1 " & 查询条件 方式来处理
dim tmp_name as string '公司名称条件
dim tmp_add as string '公司地址条件
'假设text1为公司名称输入框
if trim(text1.text)="" then
tmp_name=""
else
tmp_name='"& 公司名称='"& text1.text &"'"
end if
'假设text2为公司地址输入框
if trim(text2.text)="" then
tmp_add=""
else
tmp_add=" and 公司地址='"& text2.text &"'"
end if
'构造SQL查询语句
strsql=" select * from 客户资料 where 1=1 " & tmp_name & tmp_add
就是你输入的公司名称的值,如你在text1中输入了要查询的公司名称,则语句为:
select * from 客户资料 where 公司名称='"& text1.text &"'
如果你需要模糊查询,则语句为:
select * from 客户资料 where 公司名称='% "& text1.text &"%'