• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2806
  • Last Modified:

Refresh Report Data (DiscardSavedData)


     Hello!  I'm doing an external crystal report (*.rpt).  Using VB6 as front end and MS Access 2k
as back end.  The database is secured by a password.  The problem I'm having right now is that the reports
are not refreshed.  I've tried using the .DiscardSaveData method but I get an error "cannot open sql server"

Below is my code:
----------------------
With CrystalReport1
              .DataFiles(0) = App.Path & "\MyDB.mdb"
              .ReportFileName = App.Path & "\Reports\rptBoxTypes.rpt"
              .UserName = "Admin"
              .Password = "dbasepass" & Chr(10) & "dbasepass"
              .WindowState = crptMaximized
              .Formulas(0) = "AgentCode='" & gstrAgentCode & "'"
             .SelectionFormula = "{qryPaymentsNBalances.DatePosted} >= #" & FromDate & "# AND {qryPaymentsNBalances.DatePosted} <= #" & _
                                  ToDate & "#"
              .ReportTitle = "Box Types"
              .DiscardSavedData = True
              .Action = 1
End With
----------------------

     How can I make the report refresh it's data?  BTW, am I doing the right way to open a crystal report?
Or there are better ways?  If I'll change my back end to SQL would this code still works?


     I'm now in great trouble.  All the while I thought I was really opening the database and getting the data there but in fact I wasn't I was just opening the report and no database connection was made :(  That's why I'm not getting fresh data.  The code I've been using is not working :(  Any ideas on how would I connect to the data source (Access 2k and passworded)?  I'm doing an external crystal report file and I'm not using the crystal report viewer but instead I'm using the Crystal Report Application component.

Thanks,

enzo c",)

0
enzoy
Asked:
enzoy
  • 6
  • 4
1 Solution
 
mlmccCommented:
Try this

Open the report in CR
Click FILE
Ensure SAVE DATA WITH REPORT is not checked.

Try your report.

What references are you using for Crystal?

Similar code will work with SQL.

mlmcc

0
 
enzoyAuthor Commented:
>>Open the report in CR
>>Click FILE
>>Ensure SAVE DATA WITH REPORT is not checked.
I've tried unchecking SAve DAta with Report.  It still won't work.  I found out that I have a wrong database path.  But now I have corrected the database path.  But there's a new error that came up "Error created by database dll".  It seems that I can't connect to the database.

>>>Similar code will work with SQL
If it will be the same, then where would I have to put the login info for the sql server?

thanks,

enzo
0
 
mlmccCommented:
"Error created by database dll".  
Usually indicates you are missing some required CR dlls.

What references are you using for Crystal?


Runtime files for CR8

http://support.crystaldecisions.com/library/kbase/articles/c2008238.asp

Error detected
http://support.crystaldecisions.com/communityCS/TechnicalPapers/cr_error_detected_by_db_dll.pdf.asp

mlmcc
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
enzoyAuthor Commented:
I made it work by setting the data source of the report to "Database files".  Before the data source of the report is set to "More Data Sources > OLE DB".

So the code I'm using are for reports that uses "Database files" as data source.  How about if I'm gonna use OLE DB what would be code?  Specially if my back end would be an SQL server how would that be possible be?

thanks,

enzo
0
 
mlmccCommented:
Here is the code I use to run reports from an MS SQL database.

Option Explicit
    Dim crApp As CRAXDRT.Application
    Dim crRpt As CRAXDRT.Report

Public Sub crPreview_Report( )
'
'   Check if report is already in use
'
    If IsObject(crRpt) Then
       Set crRpt = Nothing
    End If

'
'   Open report
'
    Set crApp = New CRAXDRT.Application

    Set crRpt = crApp.OpenReport("FULL REPORT PATH", 1)
   
    crRpt.RecordSelectionFormula = "{TableName.DepartmentID} = "


'
'   Set flags for CRViewer
'
    crRpt.MorePrintEngineErrorMessages = False
    crRpt.EnableParameterPrompting = False
    crRpt.DiscardSavedData
   
'
' Set the viewer's report source to the Report object
'
    Me.rptCRViewer.ReportSource = crRpt
    Me.rptCRViewer.ViewReport
    Me.Show

End Sub

Public Sub crPrint_Report( )

'
'   Check if report is already in use
'
        If IsObject(crRpt) Then
           Set crRpt = Nothing
        End If

'
'   Open report
'
        Set crApp = New CRAXDRT.Application

        Set crRpt = crApp.OpenReport("FULL REPORT PATH", 1)
   
        crRpt.RecordSelectionFormula = "{TableName.DepartmentID} = "


'
'   Set flags for CRViewer
'
        crRpt.MorePrintEngineErrorMessages = False
        crRpt.EnableParameterPrompting = False
        crRpt.DiscardSavedData

'
'   Print Report
'
       crRpt.PrintOut False
       Unload Me

End Sub


We use integrated security so there is no need for a separate logon to the database.  Add the CR Designer Runtime Library as a reference and the CRViewer as a component.  This code goes on the form with the CRViewer.

mlmcc
0
 
enzoyAuthor Commented:
I made it work by setting the data source of the report to "Database files".  Before the data source of the report is set to "More Data Sources > OLE DB".

So the code I'm using are for reports that uses "Database files" as data source.  How about if I'm gonna use OLE DB what would be code?  Specially if my back end would be an SQL server how would that be possible be?

thanks,

enzo
0
 
enzoyAuthor Commented:
thanks for single handedly helping me out, although you didnt have help me directly but through the link you gave me I somehow got the idea may be there's a driver issue on my problem and also thanks for the sample code ;) 250 pts for you ;)
0
 
enzoyAuthor Commented:
Another thing mlmcc if you would be so kind enough just a simple one.  Which way is best to use my code(using crystal report application component) or your code (using crviewer and CR Designer Runtime Library)  What are the PROs and CONs?

Thanks,

enzo
0
 
mlmccCommented:
I don't really know.  I took my code from a reference book I use alot and from this web site.  The reference is
The Complete Reference Crystal Reports by george Peck.

I find my code simple and easy to use.  It is also flexible and can be adapted to most situations.

The methodolgies are very similar.  Since our database uses integrated security i don't need to pass logon information.  I'd have to look into yours more fully to make a complete judgement.

The way I look at it is, use the code you understand that does the job.

mlmcc
0
 
enzoyAuthor Commented:
oh ok thanks for your tips!

thanks,

enzo
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now