用来做查询,查询的条件由编辑框输入,考虑到查询条件可以为空(全空情况我另做判断了)。所以语句我是如下写的,但有错,呵呵,大家帮忙看看 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)& "'")
& 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)& "'")
& iif(trim(txtid) ="","","trim(AdodcUser.Recordset.Fields("id"))="& "'" &trim(txtid)& "'") _
& iif(trim(txtname) ="","","trim(AdodcUser.Recordset.Fields("name"))="& "'" &trim(txtname)& "'")
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
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