以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  日期筛选无法跨2013筛选代码  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=28137)

--  作者:youyuweinihao
--  发布时间:2013/1/20 9:17:00
--  日期筛选无法跨2013筛选代码

Dim s As Date

Dim ids As String

Dim cnt As Integer

Dim nms As String

Syscmd.Filter.UnFilter()

s = Forms("窗口4").Controls("DateTimePicker1").value

For Each dr As DataRow In DataTables("会员信息").DataRows

   Dim dt As Date = dr("阳历生日")

   Dim dy As Date = dr("出生日期")

   dt =  New Date(s.Year,dt.Month,dt.Day)

   dy =  New Date(s.Year,dy.Month,dy.Day)

    If dt = s Or dy = s Then

        cnt = cnt + 1

        ids = ids & "," & dr("_Identify")

    End If

Next

 

If cnt > 0 Then

    Tables("会员信息").Filter = "[_Identify] In (" & ids.Trim(",") &")"

   Else

     messagebox.show("没有过生日的人")

End If
此主题相关图片如下:qq截图20130119203327.jpg
按此在新窗口浏览图片


--  作者:youyuweinihao
--  发布时间:2013/1/20 9:18:00
--  
求解,为什么啊2013前都可以进行正常筛选,2013后就不行
--  作者:狐狸爸爸
--  发布时间:2013/1/21 9:05:00
--  
这个和2013无关的,农历并非每天都有相同的阳历日期,反之亦然,所以你的代码存在逻辑问题,出错是才是正常的。
--  作者:lin_hailun
--  发布时间:2013/1/21 9:18:00
--  
 楼主,你的代码,或者你的数据有问题吧?贴出你自己写的代码,上传你有的数据或者项目。
--  作者:youyuweinihao
--  发布时间:2013/1/22 10:28:00
--  

狐爸我的代码要怎么修改呢

谢谢


--  作者:lin_hailun
--  发布时间:2013/1/22 10:44:00
--  
以下是引用youyuweinihao在2013-1-22 10:28:00的发言:

狐爸我的代码要怎么修改呢

谢谢


如果之前正常的话,就不可能是代码出错了。看看你的表数据里是否有不符合规则的数据,比如空行等的。

这句
For Each dr As DataRow In DataTables("会员信息").DataRows

改成
For Each dr As DataRow In DataTables("会员信息").Select("阳历生日 is not null And 出生日期 is not null")

--  作者:youyuweinihao
--  发布时间:2013/1/22 10:52:00
--  

之前是正常的

2013年以前筛选都是正常的

以换2013筛选就出错


--  作者:lin_hailun
--  发布时间:2013/1/22 11:03:00
--  
以下是引用youyuweinihao在2013-1-22 10:52:00的发言:

之前是正常的

2013年以前筛选都是正常的

以换2013筛选就出错


嗯嗯,明白了,应该是2月29日的问题。

代码需要这样改一下。

Dim s As Date
Dim ids As String
Dim cnt As Integer
Dim nms As String
Syscmd.Filter.UnFilter()
s = Forms("窗口4").Controls("DateTimePicker1").value

For Each dr As DataRow In DataTables("会员信息").DataRows 
    Dim dt As Date = dr("阳历生日")  
    Dim dy As Date = dr("出生日期")
   
    Dim day As Integer = dt.Day
    If dt.Month = 2 AndAlso dt.Day = 29 AndAlso Date.IsLeapYear(s.Year) = False Then
        day = 28
    End If
    dt =  New Date(s.Year,dt.Month, day)

    day = dy.Day
    If dy.Month = 2 AndAlso dy.Day = 29 AndAlso Date.IsLeapYear(s.Year) = False Then
        day = 28
    End If   
    dy =  New Date(s.Year,dy.Month,day)
   
    If dt = s Or dy = s Then      
        cnt = cnt + 1     
        ids = ids & "," & dr("_Identify")     
    End If 
Next

If cnt > 0 Then 
    Tables("会员信息").Filter = "[_Identify] In (" & ids.Trim(",") &")"  
Else
    messagebox.show("没有过生日的人")
End If