每次运行程序时,vb6中的数据环境都不起作用! [英] Data Environment in vb6 does not work everytime I run the program !

查看:65
本文介绍了每次运行程序时,vb6中的数据环境都不起作用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想报告每日收入支出帐户。我正在为此报告使用数据环境,并将日期字段作为组字段。问题是,每次运行程序时,数据有时会出现,有时它只显示空白。我不明白为什么会发生这种情况,原因是什么?





I want to make a report of daily income expense account. I am using a data environment for this report and made date field as group field. The problem is that every time I run the program the data sometimes appears and sometime it's showing just blank. I can't understand why this is happening and what is the reason for it?


Private Sub CmdOk_Click()

Dim RsRojmelIncome As New ADODB.Recordset
Dim RsRojmelExp As New ADODB.Recordset
Dim RsTempRojmel As New ADODB.Recordset
cn.Execute "delete from TempRojmel"

RsRojmelIncome.Open " select * from Rojmel where Date1 BETWEEN #" & Format(DTPicker1.Value, "MM/DD/yyyy") & "# AND #" & Format(DTPicker2.Value, "MM/DD/YYYY") & "# And IncExp = 'ytJtf'", cn, adOpenKeyset, adLockOptimistic
RsRojmelExp.Open " select * from Rojmel where Date1 BETWEEN #" & Format(DTPicker1.Value, "MM/DD/yyyy") & "# AND #" & Format(DTPicker2.Value, "MM/DD/YYYY") & "# And IncExp = 'SJtf'", cn, adOpenKeyset, adLockOptimistic
Set RsTempRojmel = New ADODB.Recordset

RsTempRojmel.Open "Select * from TempRojmel", cn, adOpenKeyset, adLockOptimistic

If RsRojmelIncome.RecordCount >= 1 Then

For i = 1 To 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
Next i
End If

If RsRojmelExp.RecordCount >= 1 Then

For j = 1 To 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
Next j
End If




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

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").Name

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.Show
RptRojmel.Refresh

End Sub

推荐答案

在退出前尝试关闭记录集。



...



RsRojmelIncome.Close

RsRojmelExp.Close

RsTempRojmel.Close

RsTempRojmel.Close



设置RsRojmelIncome = Nothing

设置RsRojmelExp = Nothing

设置RsTempRojmel = Nothing

设置RsTempRojmel = Nothing



退出子
Try closing your recordsets before exiting.

...

RsRojmelIncome.Close
RsRojmelExp.Close
RsTempRojmel.Close
RsTempRojmel.Close

Set RsRojmelIncome = Nothing
Set RsRojmelExp = Nothing
Set RsTempRojmel = Nothing
Set RsTempRojmel = Nothing

Exit Sub


这篇关于每次运行程序时,vb6中的数据环境都不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆