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

How can i refresh report values from the database

I have a vb application that pulls up a crystal report.
I can view the report but for some reason i cannot view updated values from the database.
Can somebody help me on how to refresh the report so that any data added or removed will show up on the prompts for the report.
Below is my code,

    Set Report = Appl.OpenReport("c:\crystal_report.rpt")
    Report.DiscardSavedData

    Report.Database.Tables(1).SetLogOnInfo "machinename", "databasename", "userid", "password"
   
    CRViewer1.DisplayToolbar = True
    CRViewer1.EnableRefreshButton = True

    CRViewer1.ReportSource = Report
    CRViewer1.ViewReport

I am connecting to an oracle database through an odbc connection
   
0
dayiku
Asked:
dayiku
  • 2
  • 2
1 Solution
 
weiroblpayCommented:
I believe you can get rid of saved data in 2 ways.  One of them you already have done by doing Report.DiscardSavedData
If you have access to the report file itself, and can edit it then you should check the File menu and see if the "Save data with report" menu item is checked. If it is, then uncheck it and save the report. That usually solves it.

If that doesn't work then try the ReadRecords method of the report object like this:
Set Report = Appl.OpenReport("c:\crystal_report.rpt")
    Report.DiscardSavedData

    Report.Database.Tables(1).SetLogOnInfo "machinename", "databasename", "userid", "password"
    Report.ReadRecords

If you still can't get it to work, please let us know which version of Crystal reports your're using.

Good luck,

Ron
0
 
dayikuAuthor Commented:

That did not work.
I opened up the file in Crystal Reports and the "Save data with report" was unchecked"
I then added the Report.ReadRecords to my file but i still get the same values.
I have version 8.5
0
 
weiroblpayCommented:
The following code has worked for me for quite a while. This code is from an app in VB6 using Crystal Developer 8.5 to create the report files. The application opens the report files in a form with the crviewer.dll

Code:

Dim crxTable As CRAXDRT.DatabaseTable   ' crystal reports API - table object
   Dim m_crxApp as CRAXDRT.Application  
   
      Set m_crxApp = New CRAXDRT.Application

      ' log on to the server - if we don't do this here, the report can't be viewed
      m_crxApp.LogOnServer "P2SODBC.DLL", DSN_Name, Database_Name, Login_Name, Password

For SQL Server Database

      ' open report object
      Set m_crxReport = m_crxApp.OpenReport(ReportFileName_And_Path, 1)
     
      ' set each table to the correct DSN, DB, UID and PWD
      ' this is different for SQL databases - this allows us to use different
      ' settings than originally stored in the report
     
      For Each crxTable In m_crxReport.Database.Tables
         crxTable.SetLogOnInfo DSN_Name, Database_Name, Login_Name, Password
      Next crxTable



For Access Database
     
      Set m_crxApp = New CRAXDRT.Application
     
      ' open report object
      Set m_crxReport = m_crxApp.OpenReport(ReportFileName_And_Path, 1)
     
      ' make sure each table in the report points to the correct database ....
      ' this will allow you to use any name for the database, instead of just the
      ' one that was saved with the report file - and allow us to store the reports
      ' anywhere we want instead of in the same folder with the database.
     
      For Each crxTable In m_crxReport.Database.Tables
         crxTable.Location = Database_Name_Path
      Next crxTable


Perhaps your report is not connecting to the Database properly and therefore only shows the saved records?

Good luck.
0
 
dayikuAuthor Commented:
Actually it seems to be connecting properly.
Do you have the instructions for connecting to an oracle database?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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