以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  跨表统计获得日期列该月的总额  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89960)

--  作者:js4222
--  发布时间:2016/9/2 2:51:00
--  跨表统计获得日期列该月的总额
If e.DataCol.Name = "姓名" Then
    Dim Filter As String = "[姓名] = \'" & e.NewValue & "\'"
    Dim m As Integer = CurrentTable.Current("日期").Month
    Dim y As Integer = CurrentTable.Current("日期").Year
    Dim dt1 As New Date(y, m, 1)
    Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天
    Filter = "日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#"
    e.DataRow("借支") = DataTables("借支表").Compute("Sum(金额)","[姓名] = \'" & e.NewValue & "\'")
End If
以上代码,老是统计借支表该姓名下的所有借支,而不会按照该月来统计图片点击可在新窗口打开查看

--  作者:js4222
--  发布时间:2016/9/2 2:51:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:测试.table


--  作者:js4222
--  发布时间:2016/9/2 3:20:00
--  
If e.DataCol.Name = "姓名" Then
    Dim Filter As String = "[姓名] = \'" & e.NewValue & "\'"
    Dim m As Integer = CurrentTable.Current("日期").Month
    Dim y As Integer = CurrentTable.Current("日期").Year
    Dim dt1 As New Date(y, m, 1)
    Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天
    Filter = "日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#"
    e.DataRow("借支") = DataTables("借支表").Compute("Sum(金额)",filter)
End If
这样如果一重置列,整列借支都是同一个数字了
代码要如何写才是正确的呢

--  作者:2900819580
--  发布时间:2016/9/2 8:59:00
--  
If e.DataCol.Name = "姓名" Then
    Dim Filter As String = "[姓名] = \'" & e.NewValue & "\'"
    Dim m As Integer = CurrentTable.Current("日期").Month
    Dim y As Integer = CurrentTable.Current("日期").Year
    Dim dt1 As New Date(y, m, 1)
    Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天
    Filter = filter & " and 日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#"
    e.DataRow("借支") = DataTables("借支表").Compute("Sum(金额)",filter)
End If

试一下

--  作者:js4222
--  发布时间:2016/9/2 16:19:00
--  
以下是引用2900819580在2016/9/2 8:59:00的发言:
If e.DataCol.Name = "姓名" Then
    Dim Filter As String = "[姓名] = \'" & e.NewValue & "\'"
    Dim m As Integer = CurrentTable.Current("日期").Month
    Dim y As Integer = CurrentTable.Current("日期").Year
    Dim dt1 As New Date(y, m, 1)
    Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天
    Filter = filter & " and 日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#"
    e.DataRow("借支") = DataTables("借支表").Compute("Sum(金额)",filter)
End If

试一下
不行,重置列的话,鼠标选择哪一个日期的,重置后,“借支”列的数据都变成该行日期的统计


--  作者:有点蓝
--  发布时间:2016/9/2 16:24:00
--  
12
[此贴子已经被作者于2016/9/2 16:24:05编辑过]

--  作者:js4222
--  发布时间:2016/9/2 16:24:00
--  
以下是引用有点蓝在2016/9/2 16:24:00的发言:
上例子说明
例子2楼


--  作者:有点蓝
--  发布时间:2016/9/2 16:56:00
--  
If e.DataCol.Name = "姓名" Then
    Dim Filter As String = "[姓名] = \'" & e.NewValue & "\'"
    Dim m As Integer = e.DataRow("日期").Month
    Dim y As Integer = e.DataRow("日期").Year
    Dim dt1 As New Date(y, m, 1)
    Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天
    Filter = filter & " and 日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#"
    e.DataRow("借支") = DataTables("借支表").Compute("Sum(金额)",Filter)
End If

--  作者:狐狸爸爸
--  发布时间:2016/9/2 16:59:00
--  

除了4楼的问题,还有一个问题,这个问题出在:

CurrentTable.Current

 

应该用e.Datatow

 

参考:

http://www.foxtable.com/webhelp/scr/0604.htm

 

 


--  作者:js4222
--  发布时间:2016/9/2 17:17:00
--  
以下是引用狐狸爸爸在2016/9/2 16:59:00的发言:

除了4楼的问题,还有一个问题,这个问题出在:

CurrentTable.Current

 

应该用e.Datatow

 

参考:

http://www.foxtable.com/webhelp/scr/0604.htm

 

 可以了。谢谢。代码编程是短板,没办法,只能什么不懂就来问,谢谢大家的帮助