我想报告每日收入支出帐户。我在此报告中使用data environment
,并将日期字段设为组字段。问题是,每次运行程序时,数据有时会出现,有时它只显示空白。我不明白为什么会发生这种情况,原因是什么?
我通过数据环境工具直接绑定表
代码在这里
Private Sub CmdOk_Click()
Dim RsRojmelIncome As New ADODB.Recordset
Dim RsRojmelExp作为新的ADODB.Recordset
Dim RsTempRojmel作为新的ADODB.Recordset
cn.Execute“从TempRojmel删除”RsRojmelIncome.Open“select * from Rojmel,其中Date1 BETWEEN#”&格式(DTPicker1.Value,“MM / DD / yyyy”)& “#AND#”& 格式(DTPicker2.Value,“MM / DD / YYYY”)& “#And IncExp ='ytJtf'”,cn, adOpenKeyset,adLockOptimistic
RsRojmelExp.Open“select * from Rojmel,其中Date1 BETWEEN#”&格式(DTPicker1.Value,“MM / DD / yyyy”)& “#AND#”& 格式(DTPicker2.Value,“MM / DD / YYYY”)& “#和IncExp ='SJtf'”,cn, adOpenKeyset,adLockOptimistic
设置RsTempRojmel = New ADODB.Recordset
RsTempRojmel.Open“从TempRojmel中选择*”,cn,adOpenKeyset,adLockOptimistic
如果RsRojmelIncome.RecordCount> = 1那么
对于i = 1到RsRojmelIncome.RecordCount RsTempRojmel.AddNew RsTempRojmel.Fields(“Id”)= i RsTempRojmel.Fields(“IncVigat”)= RsRojmelIncome.Fields(“Vigat”)RsTempRojmel.Fields(“Date1”)= RsRojmelIncome.Fields(“Date1”)RsTempRojmel.Fields(“IncAmount”)= RsRojmelIncome.Fields(“Amount”)RsTempRojmel.Update
RsRojmelIncome.MoveNext
接下来我
结束如果如果RsRojmelExp.RecordCount> = 1那么
对于j = 1到RsRojmelExp.RecordCount RsTempRojmel.AddNew RsTempRojmel.Fields(“Id”)= j RsTempRojmel.Fields(“ExpVigat”)= RsRojmelExp.Fields(“Vigat”)RsTempRojmel.Fields(“Date1”)= RsRojmelExp.Fields(“Date1”)RsTempRojmel.Fields(“ExpAmount”)= RsRojmelExp.Fields(“Amount”)RsTempRojmel.Update
RsRojmelExp.MoveNext
下一个j
结束如果如果DataEnvironment1.rsCommand1_Grouping.State = 0那么
DataEnvironment1.rsCommand1_Grouping.Open“SHAPE {SELECT * FROM
TempRojmel
} AS Command1 COMPUTE Command1,SUM(Command1.'IncAmount') AS Aggregate1,SUM(Command1.'ExpAmount')AS Aggregate2,CALC (Aggregate1-Aggregate2)为NetProf1 BY'Date1'“, DataEnvironment1.Connection1,adOpenKeyset,adLockOptimistic结束如果
RptRojmel.Sections(“Section7”)。Controls.Item(“Text1”)。DataField = DataEnvironment1.rsCommand1_Grouping.Fields(“NetProf1”)。Name。
RptRojmel.Sections(“Section7”)。Controls.Item(“Text2”)。DataField = DataEnvironment1.rsCommand1_Grouping.Fields(“Aggregate1”)。姓名
RptRojmel.Sections(“Section4”)。Controls.Item(“LblDate1”)。Caption = DTPicker1.Value
RptRojmel.Sections(“Section4”)。Controls.Item(“LblDate2”)。Caption = DTPicker2.Value
RptRojmel.Refresh
DataEnvironment1.rsCommand1_Grouping.Requery
RptRojmel.Refresh
结束子
答案 0 :(得分:0)
而不是
If DataEnvironment1.rsCommand1_Grouping.State = 0 Then
DataEnvironment1.rsCommand1_Grouping.Open " SHAPE {SELECT * FROM TempRojmel} AS Command1 COMPUTE Command1, SUM(Command1.'IncAmount') AS Aggregate1, SUM(Command1.'ExpAmount') AS Aggregate2,CALC (Aggregate1-Aggregate2) as NetProf1 BY 'Date1' ", DataEnvironment1.Connection1, adOpenKeyset, adLockOptimistic
End If
尝试使用
If DataEnvironment1.rsCommand1_Grouping.State = adStateOpen Then
DataEnvironment1.rsCommand1_Grouping.Close
End If
DataEnvironment1.rsCommand1_Grouping.Open " SHAPE {SELECT * FROM TempRojmel} AS Command1 COMPUTE Command1, SUM(Command1.'IncAmount') AS Aggregate1, SUM(Command1.'ExpAmount') AS Aggregate2,CALC (Aggregate1-Aggregate2) as NetProf1 BY 'Date1' ", DataEnvironment1.Connection1, adOpenKeyset, adLockOptimistic