用来做查询,查询的条件由编辑框输入,考虑到查询条件可以为空(全空情况我另做判断了)。所以语句我是如下写的,但有错,呵呵,大家帮忙看看    AdodcUser.RecordSource = "select * from login where " _
            & iif(trim(txtid) ="","","trim(AdodcUser.Recordset.Fields(""))="& "'" &trim(txtid)& "'") _
            & iif(trim(txtname) ="","","trim(AdodcUser.Recordset.Fields("name"))="& "'" &trim(txtname)& "'") _
            & iif(trim(txtid) ="","","trim(AdodcUser.Recordset.Fields("group"))="& "'" &trim(txtid)& "'")

解决方案 »

  1.   

    发的有点错,重发    AdodcUser.RecordSource = "select * from login where " _
                & iif(trim(txtid) ="","","trim(AdodcUser.Recordset.Fields("id"))="& "'" &trim(txtid)& "'") _
                & iif(trim(txtname) ="","","trim(AdodcUser.Recordset.Fields("name"))="& "'" &trim(txtname)& "'")
      

  2.   

    trim(AdodcUser.Recordset.Fields("id"))那像上面的语句要怎么写入字符串?Fields("id")  中有引号,且 id 是表的字段名
      

  3.   

    按二楼意思,修改后.但在trim(AdodcUser.Recordset.Fields("id"))出错,就是由 " 引起的  Dim strid As String
        strid = ""
        If Trim(txtid) <> "" Then strid = "AdodcUser.Recordset.Fields("id") =" + "'" + Trim(txtid) + "'" + " and"
        
        Dim strname As String
        strname = ""
        If Trim(txtname) <> "" Then strname = "AdodcUser.Recordset.Fields("name") =" + "'" + Trim(txtname) + "'" + " and"
        
        Dim strqx As String
        strqx = ""
        If Trim(Comboqx.Text) <> "" Then strqx = "AdodcUser.Recordset.Fields("level") =" + "'" + Trim(Comboqx.Text) + "'"
        
        AdodcUser.RecordSource = "select * from login where " + strid + strname + strqx
        
       
        AdodcUser.Refresh
      

  4.   

    dim constr as string
    dim conCount as long
    If Trim(txtid) <> "" Then 
       concount=concount+1
       constr = "id='" & Trim(txtid) & "'"
    end if
    If Trim(txtname) <> "" Then
         if concount>0 then
            constr =constr &  " and  name='" & Trim(txtname) & "'" 
         else
            concount=concount+1
            constr =constr &  " name='" & Trim(txtname) & "'" 
         end if
    end if
    If Trim(Comboqx.Text) <> "" Then 
        if concount>0 then
            constr =constr  & " and level='" & Trim(Comboqx.Text) & "'"
        else
            constr =constr  & " level='" & Trim(Comboqx.Text) & "'"
        end if
    end if
    if concount>0 then
       constr=" where " & constr
    end if
    AdodcUser.RecordSource = "select * from login " + constr