Office中国论坛/Access中国论坛

标题: 多条件筛选 [打印本页]

作者: cangqiong    时间: 2010-4-14 11:34
标题: 多条件筛选
本帖最后由 cangqiong 于 2010-4-14 13:49 编辑

[attach]41972[/attach]

打开窗体时,就会弹出这个界面,然后填写条件,可以“填加条件”和“删除条件”。点确定就会查询出想要的结果。
这个怎么做,有人会吗?
作者: beenet    时间: 2010-4-14 15:10
思路:
动态组成查询条件,SQL语句字符串相加而成。
dim StrSQL as string
StrSQL="select... " & "条件1" & "条件2” & "from..."
docmd.runsql strsql
作者: michael100    时间: 2010-4-14 15:53
我是这样搞了,不知道合不合你用:
    strWhereForm = "" '设定初始值-空字符串   
        '判断【客户】条件是否有输入的值
    If Not IsNull(Me.客户简称) Then
        '有输入
        strWhereForm = strWhereForm & "( 客户简称 = '" & Me.客户简称 & "') AND "
    End If
            '判断【客户款号】条件是否有输入的值
    If Not IsNull(Me.客户款号) Then
        '有输入
        strWhereForm = strWhereForm & "( 客户款号 = '" & Me.客户款号 & "') AND "
    End If
    '判断【款号】条件是否有输入的值
    If Not IsNull(Me.公司款号) Then
        '有输入
        strWhereForm = strWhereForm & "( 公司款号 = '" & Me.公司款号 & "') AND "
    End If
    '判断【订单号码】条件是否有输入的值
    If Not IsNull(Me.订单号码) Then
        '有输入
        strWhereForm = strWhereForm & "( 单据号码 = '" & Me.订单号码 & "') AND "
    End If
    '判断【制单号码】条件是否有输入的值
    If Not IsNull(Me.制单号码) Then
        '有输入
        strWhereForm = strWhereForm & "( 辅助单据 = '" & Me.制单号码 & "') AND "
    End If  
        '判断【码数】条件是否有输入的值
   ' If Not IsNull(Me.码数) Then
        '有输入
      '  strWhereForm = strWhereForm & "( 码数 = " & Me.码数 & ") AND "
'   End If   
        '判断【起始日期】条件是否有输入的值
    If Not IsNull(Me.[起始日期]) Then
        '有输入
        strWhereForm = strWhereForm & "( 日期 >= #" & Me.起始日期 & "# ) AND "
          End If   
    '判断【结束日期】条件是否有输入的值
    If Not IsNull(Me.[结束日期]) Then
        '有输入
        strWhereForm = strWhereForm & "( 日期 <= #" & Me.结束日期 & "# ) AND "
    End If
   
    If Len(strWhereForm) > 0 Then
        '有输入条件
        strWhereForm = Left(strWhereForm, Len(strWhereForm) - 5)
    End If   
   Me.窗体1.Form.Filter = strWhereForm
   Me.窗体1.Form.FilterOn = True
作者: cangqiong    时间: 2010-4-14 16:04
3楼的兄弟,我也是这样用的。但这个实现不了我的功能。

2楼的兄弟能给个实例吗?

我在第二页找个思路 http://www.office-cn.net/vvb/thread-77116-1-2.html
作者: luhao    时间: 2010-7-10 07:28
网站内有实例的,细心找下。因我以前也找到。有时间找出来发给你
作者: bujiu02    时间: 2010-7-10 14:57
上面那个可以实现的吧




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3