Dim ConnDB As New ADODB.Connection
Dim ConnStr As String
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim Jz
Jz = 0
rs1.Open "牛只账面价值", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs2.Open "牛只养殖成本", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs1.MoveFirst
Do Until rs1.EOF
'If rs1("牛号") = "8785" Then
rs2.MoveFirst
Do Until rs2.EOF
If Format(rs2("日期"), "yyyy-mm-dd") >= Format(rs1("出生日期"), "yyyy-mm-dd") And Format(rs2("日期"), "yyyy-mm-dd") <= Format(rs1("断奶日期"), "yyyy-mm-dd") Then
Jz = Jz + rs2("哺乳")
End If
rs2.MoveNext
Loop
rs1("账面价值") = Jz
rs1.Update
'End If
rs1.MoveNext
Loop
'MsgBox Jz
rs1.Close
Set rs1 = Nothing
rs2.Close
Set rs2 = Nothing
MsgBox "ok"
Private Sub btnCal_Click()
Dim rst As New ADODB.Recordset
Dim startDate As String ' 开始日期,由于dlookup函数里要用作条件,需要加#号,故设置为文本型
Dim endDate As String '结束日期
rst.Open "牛只账面价值", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rst.MoveFirst
Do Until rst.EOF
startDate = "#" & Format(rst!出生日期, "yyyy-mm-dd") & "#"
endDate = "#" & Format(rst!断奶日期, "yyyy-mm-dd") & "#"
rst!账面价值 = DSum("[哺乳]", "牛只养殖成本", "[日期] between " & startDate & " And " & endDate)
rst.Update
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
MsgBox "ok"
End Sub
总记录:6篇 页次:1/1 9 1 :