表单上有若干个文本框,每个文本框均是一个查询条件的输入框,当一个或几个文本框中有text的时候,就以他们作为并列的查询条件,进行查询。以一个button的click事件来触发。应该怎么实现呢?

解决方案 »

  1.   

    sub command1_click()
        dim strwhere as string    if isnull(text1.value)=false then
            strwhere=strwhere & " and field1='" & text1.value & "'"
        end if
        if isnull(text2.value)=false then
            strwhere=strwhere & " and field2='" & text2.value & "'"
        end if
        if isnull(text3.value)=false then
            strwhere=strwhere & " and field3='" & text3.value & "'"
        end if
        dim strsql as string
        strsql="select * from tableName where field_deleted=false " & strwhere
        dim conn as stringend sub
      

  2.   

    sub command1_click()
        dim strwhere as string    if isnull(text1.value)=false then
            strwhere=strwhere & " and field1='" & text1.value & "'"
        end if
        if isnull(text2.value)=false then
            strwhere=strwhere & " and field2='" & text2.value & "'"
        end if
        if isnull(text3.value)=false then
            strwhere=strwhere & " and field3='" & text3.value & "'"
        end if
        dim strsql as string
        strsql="select * from tableName where field_deleted=false " & strwhere
        dim strconn as string
        dim conn as new adodb.connection
        dim rs as new adodb.recordset
        conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\1.mdb;User ID=admin;Password=rr;Jet OLEDB:Database Password=1"
        rs.open conn,1,1
        do until rs.eof
            ...
            rs.movenext
        loop
        rs.close
        set rs=nothingend sub