以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于自制筛选的问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=116598)

--  作者:xwhong123
--  发布时间:2018/3/27 20:13:00
--  [求助]关于自制筛选的问题
Dim Filter As String
With e.Form.Controls("cmbProduct")
If .Value IsNot Nothing Then
Filter = "日期 = \'" & .Value & "\'"
End If

If Filter > "" Then
Tables("表A").Filter = Filter
End If

如上,这是一个筛选按钮的代码,筛选列“日期”的列数据类型为日期时间,格式为2014-02-05等,筛选条件为同样的年月日,但是我希望能将筛选条件变成满足“日期”列中的前4字符(即年份),请问是否有这样的代码能做到如果"cmbProduct"满足前4字符,就可以筛选出来

--  作者:有点蓝
--  发布时间:2018/3/27 20:20:00
--  
参考:




--  作者:xwhong123
--  发布时间:2018/3/27 20:25:00
--  
我的意思是,我的筛选框仅有2013,2014,2015,2016这几个数据,但是在选择了譬如2014后,点击我设定的按钮,能够将一个完整的日期列(2014-02-17)中的所有开头为2014的筛选出来。

--  作者:有点蓝
--  发布时间:2018/3/27 20:33:00
--  
Dim Filter As String

With e.Form.Controls("cmbProduct")
    If .Value IsNot Nothing Then
Dim d As Date = new Date(val(.Value),1,1)
        Filter = "日期 >= #" & d & "# and 日期 < #" & d.AddYears(1) & "#"
    End If
End With

If Filter > "" Then
    Tables("表A").Filter = Filter
End If

--  作者:xwhong123
--  发布时间:2018/3/27 20:34:00
--  
谢谢
--  作者:xwhong123
--  发布时间:2018/3/27 20:58:00
--  
With e.Form.Controls("cmbProduct")
   
If .Value IsNot Nothing Then
        Filter =
"编号 = \'" & .Value & "\'"
   
End If
End
With

麻烦再问一下,我将你发给我的指令输入后,的确能够筛选出日期中的年,但是当我在筛选指令中添加了上面这个指令后,筛选按钮只能筛选你给我的日期筛选,并不能对编号进行筛选,是否能够将两个筛选条件同时满足(筛选日期中的年同时筛选编号),谢谢

--  作者:wyz20130512
--  发布时间:2018/3/27 21:14:00
--  
用逻辑运算符继续连接即可!

 Filter = "日期 >= #" & d & "# And 日期 < #" & d.AddYears(1) & "# And 编号 = \'" & .Value & "\'"
[此贴子已经被作者于2018/3/27 21:16:51编辑过]

--  作者:xwhong123
--  发布时间:2018/3/27 21:29:00
--  
但是编号所在的筛选输入文本框和日期筛选输入问文本框不是一个
--  作者:有点蓝
--  发布时间:2018/3/27 21:33:00
--  
认真看一下帮助:http://www.foxtable.com/webhelp/scr/1058.htm

With e.Form.Controls("cmbCustomer")\'第一个控件的条件
    
If .Value IsNot Nothing Then
        
If Filter > "" Then
            Filter = Filter & 
" And "
        
End If
        Filter = Filter & 
"客户 = \'" & .Value & "\'"
    
End If
End
 With
With
 e.Form.Controls("cmbEmployee")\'第二个控件的条件
    
If .Value IsNot Nothing Then
        
If Filter >"" Then
            Filter = Filter & 
" And "
        
End If
        Filter = Filter & 
"雇员 = \'" & .Value & "\'"
    
End If
End
 With

--  作者:xwhong123
--  发布时间:2018/3/27 22:32:00
--  
Dim Filter As String
With e.Form.Controls("cmbProduct2")
If .Value IsNot Nothing Then
Dim d As Date = new Date(val(.Value),1,1)
Filter = "日期 >= #" & d & "# and 日期 < #" & d.AddYears(1) & "#"
End If
End With
With e.Form.Controls("cmbProduct")
    If .Value IsNot Nothing Then
        Filter = "报告编号 = \'" & .Value & "\'"
    End If
End With

If Filter > "" Then
Tables("表A").Filter = Filter
End If

现在两个指令均已经输入,但是在点击按钮时,只能读取其中一个条件,不能筛选到同时满足条件的