dim tmpName as string
if trim(text3.text)="" then
    tmpName=""
else
    tmpName=" and 姓名='"& trim(text3.text) &"'"
end ifsql="select * from A where time between #" & Text1.Text & "# and #" & Text2.Text & "#" & tmpName
这句是在ACCESS上使用,
如果在SQL上如何修改?

解决方案 »

  1.   

    sql="select * from A where time between '" & Text1.Text & "' and '" & Text2.Text & "'" & tmpName 
      

  2.   

    奇怪,我也改成这样.可是不知道为什么就是不显示数据,ACCESS的数据库尽然正常.
      

  3.   

    dim tmpName as string 
    if trim(text3.text)="" then 
        tmpName="" 
    else 
        tmpName=" and 姓名='"& trim(text3.text) &"'" 
    end if sql="select * from A where time between #" & Text1.Text & "# and #" & Text2.Text & "#" & tmpName debug.print sql '截取sql到数据库中运行
      

  4.   

    原来是ACCESS的TEXT1和TEXT2可以互换位置,SQL不行. 
     找到原因了,谢谢大家,是我自己马虎.