Private Sub Query()
If all = False Then
If Text2 = "" And text3 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '" _
& strcgmc & "%'"
ElseIf Text1 = "" And text3 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '" _
& strwcdw & "%'"
ElseIf Text1 = "" And Text2 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" _
& strhjdj & "%'"
ElseIf Text1 = "" And Text2 = "" And text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjlsj like '" _
& strhjsj & "%'"
ElseIf Text1 = "" And Text2 = "" And text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where zywcrs like '%" & strwcr & "%'"
ElseIf Text1 = "" And Text2 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & "%' and nsbjlsj like '" & strhjsj & "%'"
ElseIf Text1 = "" And text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjlsj like '" & strhjsj & "%'"
ElseIf Text1 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf Text2 = "" And text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and nsbjlsj like'" & strhjsj & "%'"
ElseIf Text2 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and nsbjldj like'" & strhjdj & "%'"
ElseIf text3 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and wcdw like'%" & strwcdw & "%'"
ElseIf Text1 = "" And Text2 = "" And text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjlsj like '" & strhjsj & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text2 = "" And text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text1 = "" And Text2 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text1 = "" And text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '" & strwcdw & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text1 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjlsj like '" & strhjsj & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf Text2 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and nsbjlsj like '" & strhjsj & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjlsj like '" & strhjsj & "%' and wcdw like '" & strwcdw & "%'"
ElseIf text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and cgmcz like '%" & strcgmc & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf Text1 = "" And Text2 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where (nsbjldj like '" & strhjdj & "% ') and (nsbjlsj like '" & strhjsj & "%') and (zywcrs like '" & strwcr & "%')"
ElseIf Text1 = "" And text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & " 'and nsbjlsj like '" & strhjsj & " 'and zywcrs like '%" & strwcr & "%'"
ElseIf Text1 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & " ' and wcdw like '%" & strwcdw & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text2 = "" And text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjlsj like '" & strhjsj & " 'and cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text2 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & " 'and cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & " 'and cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text1 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "' and nsbjldj like '" & strhjdj & " 'and nsbjlsj like'" & strhjsj & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text2 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "' and nsbjldj like '" & strhjdj & " 'and nsbjlsj like'" & strhjsj & "%'and zywcrs like '%" & strwcr & "%'"
ElseIf text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "' and cgmcz like '%" & strcgmc & " 'and nsbjlsj like'" & strhjsj & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "' and nsbjldj like '" & strhjdj & " 'and cgmcz like'%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "' and wcdw like '%" & strwcdw & "' and nsbjldj like '" & strhjdj & "%'and nsbjlsj like'" & strhjsj & "%' "
Else
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like'%" & strcgmc & "%' and wcdw like '%" & strwcdw & "%' and nsbjlsj like'" & strhjsj & "%'and nsbjldj like'" & strhjdj & "%' and zywcrs like '%" & strwcr & "%'"
End If
Else
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT"
End If
'strcgmc,strwcdw,strcgdj,strhjsj变量是前面定义的公共变量,用来传递查询窗体中的成果名称,完成单位,获奖等级,获奖时间
Adodc1.RecordSource = strsql
Adodc1.Refresh
DataGrid1.Rebind
rs.Open strsql, conn, adOpenKeyset, adLockPessimistic
Adodc1.RecordSource = strsql
Adodc1.Refresh
DataGrid1.Rebind
If rs.EOF = True And rs.BOF = True Then
MsgBox "没有找到您所需要的结果!", vbOKOnly + vbInformation, "注意"
rs.Close
Exit Sub
End If
rs.Close
'End If
End Sub