Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Updated 8-Oct-15 2:58am
v2
Comments
ZurdoDev 8-Oct-15 8:58am    
You'll have to debug it since we can't run it.
Md Jamaluddin Saiyed 8-Oct-15 9:17am    
the problem is when i debug with f8 its running completely but with f5 its works only first time ! when i pass another date its not work and i get blank datareport !!
Patrice T 24-Nov-15 18:37pm    
The debugger is more than just F5 or F8;
set break points at different places, on each breakpoint, inspect variables, parameters, anything you can, to see when and where it goes wrong.
Sergey Alexandrovich Kryukov 8-Oct-15 13:47pm    
Any specific reason to torture yourself with VB6?
—SA
Maciej Los 8-Oct-15 15:41pm    
Some of people really do like it :laugh:

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900