|
楼主 |
发表于 2021-10-7 15:28
|
显示全部楼层
这是我的全部代码:
Dim SQL As String
Dim i, J
Dim condition As String, con0 As String, con1 As String, con2 As String
On Error Resume Next
con0 = "where"
If 查询项目.Value = "交易时间" Then
con1 = "#" & 条件值1.Value & "#"
con2 = "#" & 条件值2.Value & "#"
ElseIf 查询项目.Value = "付款人账号" Or 查询项目.Value = "摘要" Or 查询项目.Value = "对方户名" Or 查询项目.Value = "对方账号" Or 查询项目.Value = "借方发生额" Or 查询项目.Value = "贷方发生额" Or 查询项目.Value = "交易后余额" Or 查询项目.Value = "余额" Or 查询项目.Value = "交易金额" Then
con1 = Val(条件值1.Value)
con2 = Val(条件值2.Value)
Else
con1 = "'" & 条件值1.Value & "'"
con2 = "'" & 条件值2.Value & "'"
End If
condition = " where " & 查询项目.Value
If 运算符.Value = "between" Then
condition = condition & " between " & con1 & " and " & con2
ElseIf 运算符.Value = "like" Then
condition = condition & " like '%" & 条件值1.Value & "%'"
Else
condition = condition & 运算符.Value & con1
End If
If 银行名称.Value = "" Then
SQL = "select *, '交行'as 银行 from 交行流水 " & condition & "" _
& "union select *,'交行党费户'as 银行 from 交行党费流水 " & condition & "" _
& "union select *,'中行'as 银行 from 中行流水 " & condition & "" _
& " union select *,'工行'as 银行 from 工行流水 " & condition & "" _
& " union select *,'建行'as 银行 from 建行流水 " & condition & ""
ElseIf 银行名称.Value <> "" Then
SQL = "select * from " & 银行名称.Value & condition
End If
Set rs = New ADODB.Recordset
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
If rs.BOF And rs.EOF Then
MsgBox "没有查到结果"
Exit Sub
end if |
|