-- 作者:裴保民
-- 发布时间:2017/9/10 1:18:00
-- 自动筛选数据
Dim ids As String Dim n As Integer = 10 \'未来天数,含今天,所以实际是未来7天 For Each dr As DataRow In DataTables("客户资料").DataRows Dim rq As String = dr("出生日期") If rq.Length = 11 Then Dim Cdt As Date = new Date(rq.SubString(0,4), rq.SubString(5,2), rq.SubString(8,2)) Dim dt1 As New Date(Date.Today.Year,Cdt.Month,Cdt.Day) Dim dt2 As New Date(Date.Today.AddDays(n).Year,Cdt.Month,Cdt.Day) If (dt1 >= Date.Today AndAlso dt1 < Date.Today.AddDays(n)) OrElse (dt2 >= Date.Today AndAlso dt2 < Date.Today.AddDays(n)) Then ids = ids & "," & dr("_Identify") Else Tables("提醒窗体_Table2").DataSource ="" End If End If Next If ids > "" Then ids = ids.Trim(",") Tables("提醒窗体_Table2").filter = "[_Identify] In (" & ids &")" Tables("提醒窗体_Table2").SetColVisibleWidth(Tables("客户资料").GetColVisibleWidth()) e.Form.Controls("shengrijijiangdaoqidekehu").text = Tables("提醒窗体_Table2").Rows.Count & " 人" End If
老师这句代码哪有问题?怎么如果数据里有符合条件的数据时显示正常,如果没有符合条件的数据是窗体表则显示所有的数据,看看原因在哪?
此主题相关图片如下:66.png

此主题相关图片如下:67.png

还有如果数据库中客户表中没有数据时会弹出一下错误提示框:
此主题相关图片如下:76.png

此主题相关图片如下:77.png

[此贴子已经被作者于2017/9/10 8:21:14编辑过]
|
-- 作者:有点甜
-- 发布时间:2017/9/10 17:04:00
--
Dim ids As String Dim n As Integer = 10 \'未来天数,含今天,所以实际是未来7天 For Each dr As DataRow In DataTables("客户资料").DataRows Dim rq As String = dr("出生日期") If rq.Length = 11 Then Dim Cdt As Date = new Date(rq.SubString(0,4), rq.SubString(5,2), rq.SubString(8,2)) Dim dt1 As New Date(Date.Today.Year,Cdt.Month,Cdt.Day) Dim dt2 As New Date(Date.Today.AddDays(n).Year,Cdt.Month,Cdt.Day) If (dt1 >= Date.Today AndAlso dt1 < Date.Today.AddDays(n)) OrElse (dt2 >= Date.Today AndAlso dt2 < Date.Today.AddDays(n)) Then ids = ids & "," & dr("_Identify") Else Tables("提醒窗体_Table2").DataSource ="" End If End If Next If ids > "" Then ids = ids.Trim(",") Tables("提醒窗体_Table2").filter = "[_Identify] In (" & ids &")" Tables("提醒窗体_Table2").SetColVisibleWidth(Tables("客户资料").GetColVisibleWidth()) e.Form.Controls("shengrijijiangdaoqidekehu").text = Tables("提醒窗体_Table2").Rows.Count & " 人" Else msgbox("没有生日的人") Tables("提醒窗体_Table2").filter = "1=2" End If
|