Office中国论坛/Access中国论坛
标题:
发票号码范围查找问题
[打印本页]
作者:
xyh2732
时间:
2011-1-3 22:47
标题:
发票号码范围查找问题
[attach]44579[/attach]请帮忙看看为什么我的发票号码不可以范围查找
作者:
tmtony
时间:
2011-1-3 23:12
Option Compare Database
Private Sub Command6_Click()
Dim db As Database
Dim Rs As Recordset
Dim qdf As QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("汇总多条件查询")
On Error GoTo Err_Command6_Click
Dim StrWhere As String '定义条件字符串
StrWhere = "" '设定初始值-空字符串
'判断【公司名称】条件是否有输入的值
If Not IsNull(Me.发票号码开始) Then
'有输入
StrWhere = StrWhere & "([发票号码]>= '" & Me.发票号码开始 & "') AND "
End If
If Not IsNull(Me.发票号码结束) Then
'【单价截止】有输入
StrWhere = StrWhere & "([发票号码] <= '" & Me.发票号码结束 & "') AND "
End If
'如果输入了条件,那么strWhere的最后肯定有" AND ",这是我们不需要的,
'要用LEFT函数截掉这5个字符。
If Len(StrWhere) > 0 Then
'有输入条件
StrWhere = Left(StrWhere, Len(StrWhere) - 5)
End If
'先在立即窗口显示一下strWhere的值,代码调试完成后可以取消下一句
'Debug.Print strWhere
'让子窗体应用窗体查询
Me.[发票总查询].Form.Filter = StrWhere
Me.[发票总查询].Form.FilterOn = True
Exit_Command6_Click:
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub
作者:
tmtony
时间:
2011-1-3 23:13
主要是发票 条件 前后加了 单引号
作者:
xyh2732
时间:
2011-1-6 12:29
哦。。原来这样,学到了,谢谢你的帮忙!
作者:
roych
时间:
2011-1-6 12:51
回复
tmtony
的帖子
奇怪~~定义那几个变量为什么都不用呢?
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3