各位朋友,请看下面代码?(为什么不能实现真正的复合多条件查询?)此问题十分着急……
Private Function prvWhereSQL() As String
Dim strResult As String If Check1.Value Then
If Trim(strResult) = "" Then
strResult = " (子公司名='" & Combo5.Text & "') order by 日期"
Else
strResult = strResult & " AND (子公司名='" & Combo5.Text & "')"
End If
End If
'其它条件类似
If Check2.Value Then
If Trim(strResult) = "" Then
strResult = "(客户名称='" & Combo4.Text & "') order by 日期"
Else
strResult = strResult & " AND (客户名称='" & Combo4.Text & "')"
End If
End If
If Check3.Value Then
If Trim(strResult) = "" Then
strResult = "(账户名='" & Combo6.Text & "') order by 日期"
Else
strResult = strResult & " AND (账户名='" & Combo6.Text & "')"
End If
End If
If Check4.Value Then
If Trim(strResult) = "" Then
strResult = "(科目名称='" & Combo8.Text & "')order by 日期"
Else
strResult = strResult & " AND (科目名称='" & Combo8.Text & "')"
End If
End If
If Check5.Value Then
If Trim(strResult) = "" Then
strResult = "金额 between " & Val(Text1.Text) & " And " & Val(Text3.Text)
Else
strResult = strResult & " AND 金额 between " & Val(Text1.Text) & " And " & Val(Text3.Text)
End If
End If
If Check6.Value Then
If Trim(strResult) = "" Then
strResult = "(经手人='" & Combo7.Text & "') order by 日期"
Else
strResult = strResult & " AND (经手人='" & Combo7.Text & "')"
End If
End If
If Check7.Value Then
If Trim(strResult) = "" Then
strResult = "(备注 like '%" + Text2.Text + "%' or 科目名称 like '%" + Text2.Text + "%')"
Else
strResult = strResult & " AND (备注 like '%" + Text2.Text + "%' or 科目名称 like '%" + Text2.Text + "%')"
End If
End If
If Check8.Value Then
If Trim(strResult) = "" Then
strResult = "(日期 between # " & DTPicker1.Value & "#" & " and " & "#" & DTPicker2.Value & "# ) order by 日期"
Else
strResult = strResult & " AND (日期 between # " & DTPicker1.Value & "#" & " and " & "#" & DTPicker2.Value & "# )"
End If
End If If Trim(strResult) = "" Then
prvWhereSQL = " "
Else
prvWhereSQL = " WHERE " & strResult
End If
End Function
Private Function prvWhereSQL() As String
Dim strResult As String If Check1.Value Then
If Trim(strResult) = "" Then
strResult = " (子公司名='" & Combo5.Text & "') order by 日期"
Else
strResult = strResult & " AND (子公司名='" & Combo5.Text & "')"
End If
End If
'其它条件类似
If Check2.Value Then
If Trim(strResult) = "" Then
strResult = "(客户名称='" & Combo4.Text & "') order by 日期"
Else
strResult = strResult & " AND (客户名称='" & Combo4.Text & "')"
End If
End If
If Check3.Value Then
If Trim(strResult) = "" Then
strResult = "(账户名='" & Combo6.Text & "') order by 日期"
Else
strResult = strResult & " AND (账户名='" & Combo6.Text & "')"
End If
End If
If Check4.Value Then
If Trim(strResult) = "" Then
strResult = "(科目名称='" & Combo8.Text & "')order by 日期"
Else
strResult = strResult & " AND (科目名称='" & Combo8.Text & "')"
End If
End If
If Check5.Value Then
If Trim(strResult) = "" Then
strResult = "金额 between " & Val(Text1.Text) & " And " & Val(Text3.Text)
Else
strResult = strResult & " AND 金额 between " & Val(Text1.Text) & " And " & Val(Text3.Text)
End If
End If
If Check6.Value Then
If Trim(strResult) = "" Then
strResult = "(经手人='" & Combo7.Text & "') order by 日期"
Else
strResult = strResult & " AND (经手人='" & Combo7.Text & "')"
End If
End If
If Check7.Value Then
If Trim(strResult) = "" Then
strResult = "(备注 like '%" + Text2.Text + "%' or 科目名称 like '%" + Text2.Text + "%')"
Else
strResult = strResult & " AND (备注 like '%" + Text2.Text + "%' or 科目名称 like '%" + Text2.Text + "%')"
End If
End If
If Check8.Value Then
If Trim(strResult) = "" Then
strResult = "(日期 between # " & DTPicker1.Value & "#" & " and " & "#" & DTPicker2.Value & "# ) order by 日期"
Else
strResult = strResult & " AND (日期 between # " & DTPicker1.Value & "#" & " and " & "#" & DTPicker2.Value & "# )"
End If
End If If Trim(strResult) = "" Then
prvWhereSQL = " "
Else
prvWhereSQL = " WHERE " & strResult
End If
End Function
解决方案 »
- 请问在XP下如何注册16位的dll
- 应用程序发生异常 unknown software exception
- 兄弟们帮帮忙,Symantec AntiVirus病毒历记录的数据库是哪个文件呀?
- ★★源码放松★★ 经典:让窗体的白色部分透明,这个可不一般。
- 我是一个初学者,哪一本java教程比较好入门,请推荐一本大家认为最优秀的java入门教材
- VB如何执行SQL语句与在Access中执行SQL语句的区别是什么???????
- 请帮我看看这个是什么原因,数据库的问题
- 郁闷啊!!在sybase中返回n条记录的sql语句怎么写?
- vb6.0 怎么调用 .dll文件 最好给个例子
- VB中Access97 换成Access2000 存入数据出现混乱?
- 请高手们做一个FORM界面,很简单,高分!!解决后马上结帐!
- 请问mshflexgrid能否在指定处插入一行?
应该在所有的判断完成后,再在strResult后加order by
If Trim(strResult) = "" Then
prvWhereSQL = " "
Else
strResult = strResult & "order by 日期"
prvWhereSQL = " WHERE " & strResult
End If
End Function
sql = "select 子公司名,科目名称,客户名称,金额,支票,账户名,经手人,日期,备注,进出账 from 资料管理 " & prvWhereSQL
那么,我应该把order by 日期 放在哪儿呢?先谢谢各位了
sql=sql & order by 日期
在我这几天的发贴中,每次几乎都有阿九的帮助,非常希望能和你进一步请教,我的QQ是6492323,如果可能的话,希望能得到你的QQ号,谢谢
取最后再组合即可.
Private Function prvWhereSQL() As String
Dim strResult As String If Check1.Value = 1 Then
If Trim(strResult) = "" Then
strResult = " (子公司名='" & Combo5.Text & "') "
Else
strResult = strResult & " AND (子公司名='" & Combo5.Text & "')"
End If
End If
'其它条件类似
If Check2.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "(客户名称='" & Combo4.Text & "') "
Else
strResult = strResult & " AND (客户名称='" & Combo4.Text & "')"
End If
End If
If Check3.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "(账户名='" & Combo6.Text & "') "
Else
strResult = strResult & " AND (账户名='" & Combo6.Text & "')"
End If
End If
If Check4.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "(科目名称='" & Combo8.Text & "') "
Else
strResult = strResult & " AND (科目名称='" & Combo8.Text & "')"
End If
End If
If Check5.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "金额 between " & Val(Text1.Text) & " And " & Val(Text3.Text)
Else
strResult = strResult & " AND 金额 between " & Val(Text1.Text) & " And " & Val(Text3.Text)
End If
End If
If Check6.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "(经手人='" & Combo7.Text & "') "
Else
strResult = strResult & " AND (经手人='" & Combo7.Text & "')"
End If
End If
If Check7.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "(备注 like '%" + Text2.Text + "%' or 科目名称 like '%" + Text2.Text + "%')"
Else
strResult = strResult & " AND (备注 like '%" + Text2.Text + "%' or 科目名称 like '%" + Text2.Text + "%')"
End If
End If
If Check8.Value = 1 Then
If Trim(strResult) = "" Then
strResult = "(日期 between # " & DTPicker1.Value & "#" & " and " & "#" & DTPicker2.Value & "# ) "
Else
strResult = strResult & " AND (日期 between # " & DTPicker1.Value & "#" & " and " & "#" & DTPicker2.Value & "# )"
End If
End If If Trim(strResult) = "" Then
prvWhereSQL = " ORDER BY 日期"
Else
prvWhereSQL = " WHERE " & strResult & " ORDER BY 日期"
End If
End Function