和我理解的不一样。
期初数据表,DataColChanged事件
Select Case e.DataCol.Name
Case "部门","年份","月度"
If e.DataRow.IsNull("部门") OrElse e.DataRow.IsNull("年份") OrElse e.DataRow.IsNull("月度")
Else
Dim ms() As String = {"一","二","三","","","六","","八"} ‘其它月份自己补上
Dim s As String = e.DataRow("月度").replace("月份","")
Dim idx As Integer = Array.IndexOf(ms,s)
If idx > -1 Then
Dim d As Date = new Date(val(e.DataRow("年份")),idx+1,1)
Dim dr As DataRow = DataTables("凭证明细").Find("部门='" & e.DataRow("部门") & "' And 日期 >=#" & d & "# And 日期 < #" & d.AddMonths(1) & "#","日期")
If dr IsNot Nothing Then
e.DataRow("期初") = dr("余额")
End If
dr = DataTables("凭证明细").Find("部门='" & e.DataRow("部门") & "' And 日期 >=#" & d & "# And 日期 < #" & d.AddMonths(1) & "#","日期 desc")
If dr IsNot Nothing Then
e.DataRow("期末") = dr("余额")
End If
End If
End If
End Select