Results 1 to 10 of 10

Thread: Strange problem, report repeat same details

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Strange problem, report repeat same details

    In my projects in VB6 & database SQL2005, I use a MS Access File in all client computers for the purpose of some special reports. I use crystal report 9. All are fine and OK.
    Now when the clients want to print out report that depend on the local MS Access file, mostly the first report repeat for the second one also.

    An example: The user wants to check his stock balance, he puts the period (FromDate &ToDate) and select his user name from the combobox that I placed in the Form to print report and click print button. The report display correctly. Now if he want to check the balnce of another user or the balance of another period, only the criteria details (user name, FromDate, ToDate, type) come correctly which is passed to the parameters in the report, but the details report display the same details of the first report.
    The strange is when I chcked the table in the MS Access file the data is new and correct. But in the report it come the old one. Mostly this come for the first and second time only. After this if we print report with different criteria all the reports come correctly. If we close the Form for report print and open again the same repeat for first two reports.

    What I do in my project is I collect the data from the main server SQL 2005 and insert into the table in the MS Access table. I alway delete the existing data from the access table before I insert new data. Then I call the report. But for first two times it come repeat. Really this happened about after one year I installed my project. At the time I installed it was correct. About after one year this problem come. Now I face the same problem for my two projects and one of this project is in VB6, SQL 2000, Crystal 6

    I don't know how it is happend? Any idea ?

    With regards,
    Nasreen

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: Strange problem, report repeat same details

    MS Access has a delay of a few seconds before it actually updates the database, I've had the same issue and it drove me nuts. Now, instead of a temp table, I usually create an empty ADO recordset and load the report data into it, then I use the recordset as the reports data source (I don't know if you can do this with CR, I use DataReports). Also sometimes if you close the database connection that loads the temp table before running the report it will solve the problem.

    Why not run the report directly from the SQL 2005 DB?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Strange problem, report repeat same details

    Hi wes4dbt,
    Thanks for your replay
    I have already closed all the db connections before running the report, but the result is same.
    And your suggession to use recordset instead of a temp Access file, I don't know if possible to connect a crystal report with a recordset and create reports. Any idea ?

    With regards,
    Nasreen

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Strange problem, report repeat same details

    Try closing your Access file and execute DoEvents before print

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: Strange problem, report repeat same details

    If you post the code for loading the temp table and running the report, I'd be glad to take a look at it.

    I don't know CR but I'd be suprised if you couldn't use a recordset as a data source. I would research that possibility.

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: Strange problem, report repeat same details

    Here check this thread http://www.vbforums.com/showthread.p...t=cr+recordset

    Theres more threads about this subject. I did a forum search with "cr recordset"

    Good luck

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Strange problem, report repeat same details

    Quote Originally Posted by wes4dbt
    If you post the code for loading the temp table and running the report, I'd be glad to take a look at it.

    I don't know CR but I'd be suprised if you couldn't use a recordset as a data source. I would research that possibility.
    Here is my code as it is.

    First I retreive the data from more than 5 tables in SQL2005 database and store in a MSFlex Grid. Then I insert these data to my Local Access Database table.

    VB Code Code:
    1. 'connection details of MS SQL 2005
    2.  
    3. Public Con As ADODB.Connection
    4. Public Rst As ADODB.Recordset
    5. Public Com As ADODB.Command
    6.  
    7. Set Con = New ADODB.Connection
    8. Set Com = New ADODB.Command
    9. Set Rst = New ADODB.Recordset
    10. '----------
    11.  
    12. 'connection details of MS Access
    13.  
    14. Dim PrntCon As ADODB.Connection
    15. Dim PrntRst As ADODB.Recordset
    16. Dim PrntCom As ADODB.Command
    17.  
    18. Set PrntCon = New ADODB.Connection
    19. Set PrntRst = New ADODB.Recordset
    20. Set PrntCom = New ADODB.Command
    21. '----------
    22.  
    23. Dim i As Integer
    24. Dim ConStr  As String
    25.  
    26. 'Start data retreive
    27.  
    28. ConStr = "Provider=MSDASQL.1;Password=pwd;Persist Security Info=True;User ID=usr;Data Source=MyODBC"
    29.  
    30. MsFlxGrd.Clear
    31.     MsFlxGrd.Rows = 0
    32.     Rst.open "SELECT  TT_DATE,SUM(LC_TOT_AMT) as LcAmt  FROM TT  WHERE IS_EZRMT = 1 AND TT_DATE >= '" & FrmDate & "'  AND TT_DATE <= '" & ToDate & "'  AND USR_ID = " & Me.TxtUid.Text & " AND CNCL <> 1  GROUP BY TT_DATE", Con, adOpenKeyset
    33.     If Rst.RecordCount > 0 Then
    34.         If IsNull(Rst.Fields!LcAmt) = False Then
    35.             CurRow = MsFlxGrd.Rows
    36.             MsFlxGrd.Rows = MsFlxGrd.Rows + Rst.RecordCount
    37.             FMain.pbMain.Visible = True
    38.             FMain.pbMain.Max = MsFlxGrd.Rows
    39.             For i = CurRow To MsFlxGrd.Rows - 1
    40.                 MsFlxGrd.TextMatrix(i, 0) = "EzRemit"
    41.                 MsFlxGrd.TextMatrix(i, 1) = Format(Rst.Fields!TT_DATE, "dd/mm/yyyy")
    42.                 MsFlxGrd.TextMatrix(i, 2) = "1"
    43.                 MsFlxGrd.TextMatrix(i, 3) = Rst.Fields!LcAmt
    44.                 MsFlxGrd.TextMatrix(i, 4) = "0"
    45.                 Rst.MoveNext
    46.                 FMain.pbMain.Value = i
    47.             Next i
    48.             FMain.pbMain.Value = MsFlxGrd.Rows
    49.             FMain.pbMain.Visible = False
    50.         End If
    51.     End If
    52.     Rst.Close
    53.  
    54.     Rst.open "select * from InnerTrns where Tr_Date >= '" & FrmDate & "'  AND Tr_Date <= '" & ToDate & "' AND ToUsrID = " & Me.TxtUid.Text, Con, adOpenKeyset
    55.     If Rst.RecordCount > 0 Then
    56.     CurRow = MsFlxGrd.Rows
    57.     MsFlxGrd.Rows = MsFlxGrd.Rows + Rst.RecordCount
    58.     FMain.pbMain.Visible = True
    59.     FMain.pbMain.Max = MsFlxGrd.Rows
    60.     For i = CurRow To MsFlxGrd.Rows - 1
    61.             MsFlxGrd.TextMatrix(i, 0) = "Transfer [" & Trim$(Rst.Fields!FrmUsr) & " >> " & Trim$(Rst.Fields!ToUsr) & "]"
    62.             MsFlxGrd.TextMatrix(i, 1) = Format(Rst.Fields!Tr_Date, "dd/mm/yyyy")
    63.             MsFlxGrd.TextMatrix(i, 2) = "1"
    64.             MsFlxGrd.TextMatrix(i, 3) = Rst.Fields!Tr_Amt
    65.             MsFlxGrd.TextMatrix(i, 4) = "0"
    66.             Rst.MoveNext
    67.             FMain.pbMain.Value = i
    68.         Next i
    69.         FMain.pbMain.Value = MsFlxGrd.Rows
    70.         FMain.pbMain.Visible = False
    71.     End If
    72.     Rst.Close
    73.    
    74.     Rst.open "select * from InnerTrns where Tr_Date >= '" & FrmDate & "'  AND Tr_Date <= '" & ToDate & "' AND FrmUsrID = " & Me.TxtUid.Text, Con, adOpenKeyset
    75.     If Rst.RecordCount > 0 Then
    76.     CurRow = MsFlxGrd.Rows
    77.     MsFlxGrd.Rows = MsFlxGrd.Rows + Rst.RecordCount
    78.     FMain.pbMain.Visible = True
    79.     FMain.pbMain.Max = MsFlxGrd.Rows
    80.     For i = CurRow To MsFlxGrd.Rows - 1
    81.             MsFlxGrd.TextMatrix(i, 0) = "Transfer [" & Trim$(Rst.Fields!FrmUsr) & " >> " & Trim$(Rst.Fields!ToUsr) & "]"
    82.             MsFlxGrd.TextMatrix(i, 1) = Format(Rst.Fields!Tr_Date, "dd/mm/yyyy")
    83.             MsFlxGrd.TextMatrix(i, 2) = "2"
    84.             MsFlxGrd.TextMatrix(i, 3) = "0"
    85.             MsFlxGrd.TextMatrix(i, 4) = Rst.Fields!Tr_Amt
    86.             Rst.MoveNext
    87.             FMain.pbMain.Value = i
    88.         Next i
    89.         FMain.pbMain.Value = MsFlxGrd.Rows
    90.         FMain.pbMain.Visible = False
    91.     End If
    92.     Rst.Close
    93.  
    94.  Rst.open "SELECT PV_No, PV_Date, AMT ,PV_Type  FROM EzPymnt  WHERE PV_DATE >= '" & FrmDate & "'  AND PV_DATE <= '" & ToDate & "'  AND DEPT_ID = " & Trim(TxtUid.Text), Con, adOpenKeyset
    95.     If Rst.RecordCount > 0 Then
    96.         CurRow = MsFlxGrd.Rows
    97.         MsFlxGrd.Rows = MsFlxGrd.Rows + Rst.RecordCount
    98.         FMain.pbMain.Visible = True
    99.         FMain.pbMain.Max = MsFlxGrd.Rows
    100.         For i = CurRow To MsFlxGrd.Rows - 1
    101.             MsFlxGrd.TextMatrix(i, 0) = "PV" & Rst.Fields!PV_NO & " (" & Rst.Fields!PV_Type & ")"
    102.             MsFlxGrd.TextMatrix(i, 1) = Format(Rst.Fields!PV_DATE, "dd/mm/yyyy")
    103.             MsFlxGrd.TextMatrix(i, 2) = "2"
    104.             MsFlxGrd.TextMatrix(i, 3) = "0"
    105.             MsFlxGrd.TextMatrix(i, 4) = Rst.Fields!Amt
    106.             Rst.MoveNext
    107.             FMain.pbMain.Value = i
    108.         Next i
    109.         FMain.pbMain.Value = MsFlxGrd.Rows
    110.         FMain.pbMain.Visible = False
    111.     End If
    112.     Rst.Close
    113.     Rst.open "select C_Name, C_State, C_Cntry from EzRegistr", Con, adOpenKeyset
    114.    
    115.     CName = Rst.Fields!C_name
    116.     Rst.Close
    117.     Rst.open "select * from EzAgBrnch where BrName = '" & UsrBrnch & "'", Con, adOpenKeyset
    118.     CAdd = Rst.Fields!BrAdd1 & ", " & Rst.Fields!BrAdd2 & ", " & Rst.Fields!BrTel
    119.  
    120.     Con.Close
    121.  
    122. 'end retreive
    123.  
    124. 'Start insert to local MS Access
    125.  
    126. PrntCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Reports\Ez_rpt.mdb;Persist Security Info=False"
    127. PrntCon.open
    128. PrntCom.ActiveConnection = PrntCon
    129. PrntCom.CommandText = "delete from LCStckRpt"
    130. PrntCom.Execute
    131.  
    132. For i = 0 To MsFlxGrd.Rows - 1
    133. PrntCom.CommandText = "insert into EzLCStckUnSort values ('" & Me.MsFlxGrd.TextMatrix(i, 0) & "','" & Me.MsFlxGrd.TextMatrix(i, 1) & "'," & Me.MsFlxGrd.TextMatrix(i, 2) & "," & Me.MsFlxGrd.TextMatrix(i, 3) & "," & Me.MsFlxGrd.TextMatrix(i, 4) & ")"
    134. PrntCom.Execute
    135. FMain.pbMain.Value = i
    136. Next i
    137.  
    138. Set PrntCon = Nothing
    139. Set PrntCom = Nothing
    140.  
    141. Dim CrystApp As CRAXDRT.Application
    142. Dim CrystRpt As CRAXDRT.Report
    143. Dim MyFrmDtlRpt As New FrmRptViewr
    144. Set CrystApp = New CRAXDRT.Application
    145. Set CrystRpt = CrystApp.OpenReport(App.Path & "\Reports\LCBalanceRpt.rpt")
    146.  
    147. CrystRpt.DiscardSavedData
    148. CrystRpt.ParameterFields.GetItemByName("FrmDate").AddCurrentValue (FrmDate)
    149. CrystRpt.ParameterFields.GetItemByName("ToDate").AddCurrentValue (ToDate)
    150. CrystRpt.ParameterFields.GetItemByName("User").AddCurrentValue (CmbUser.Text)
    151. CrystRpt.ParameterFields.GetItemByName("CName").AddCurrentValue (CName)
    152. CrystRpt.ParameterFields.GetItemByName("CAdd").AddCurrentValue (CAdd)
    153.  
    154.  
    155. MyFrmDtlRpt.CRViewer91.ReportSource = CrystRpt
    156. MyFrmDtlRpt.CRViewer91.Refresh
    157. MyFrmDtlRpt.CRViewer91.ViewReport
    158.  
    159. Do While MyFrmDtlRpt.CRViewer91.IsBusy
    160. DoEvents
    161. Loop
    162. MyFrmDtlRpt.CRViewer91.Zoom 100
    163.  
    164. MyFrmDtlRpt.Caption = MyFrmDtlRpt.Caption & " (" & Me.Caption & ")"
    165. MyFrmDtlRpt.Show
    166.  
    167. Set CrystApp = Nothing
    168. Set CrystRpt = Nothing

    I hope you may check these codes and suggest a solution for my problem

    With regards,
    Nasreen
    Last edited by nasreen; Aug 8th, 2008 at 06:24 AM. Reason: Modification

  8. #8
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: Strange problem, report repeat same details

    Instead of using a temp table for the report, load the data into a ADO Recordset.

    Code:
    Dim rsRpt as New Adodb.Recordset
    
        With rsRpt
            ' Create Recordset Fields (Columns) here
            .Fields.Append "Field1", adVarChar, 80
            .Fields.Append "Field2", adInteger
            .CursorType = adOpenKeyset
            .LockType = adLockOptimistic
            .Open
        End With
    
        For i = 0 To MsFlxGrd.Rows - 1
            rsRpt.Addnew
            .
            .
            .
            rsRpt.Update
        Next i
    Then set the recordset as the reports data source, see Post #6

    BTW, Rst.Fields!LcAmt can be shortened to Rst!LcAmt

    Good Luck
    Last edited by wes4dbt; Aug 8th, 2008 at 10:51 AM.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Strange problem, report repeat same details

    Hi Mr. wes4dbt

    Thanks a lot for your valuable advices.

    I used the method suggested by you and it works me fine.

    And I have two simple doubts I faced in my work with this method. In my temp Access file table there is a field with datatype Memo. I didn't find any datatype in Adodb.Recordset that matches with Memo type of Access file. So What datatype I can use as most suitable for Memo in ADO Recordset ?
    And in the code for extract a recordset to CR:
    VB Code Code:
    1. Rpt.Database.SetDataSource rs, 3, 1
    What is the use of parameter [data Tag]? in this case (3)

    And another doubt I want clarify is, how we can run a select query from this Recordset ?

    Is it is possible to select from a recordset as we do from a table ?

    Thanks once again

    With regards,
    Nasreen
    Last edited by nasreen; Aug 9th, 2008 at 10:36 AM.

  10. #10
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: Strange problem, report repeat same details

    What is the use of parameter [data Tag]? in this case (3)
    I don't understand what your asking.


    And I have two simple doubts I faced in my work with this method. In my temp Access file table there is a field with datatype Memo. I didn't find any datatype in Adodb.Recordset that matches with Memo type of Access file. So What datatype I can use as most suitable for Memo in ADO Recordset ?
    Try using ".Fields.Append "memofield", adVariant

    Is it is possible to select from a recordset as we do from a table ?
    ADO recordsets do have a "Filter" method. rs.Filter "field1 = 'abc'". But since your loading the recordset in a loop, why not filter the records then?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width