We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How can i refresh report values from the database

dayiku
dayiku asked
on
Medium Priority
309 Views
Last Modified: 2010-05-01
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
   
Comment
Watch Question

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

Author

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
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Actually it seems to be connecting properly.
Do you have the instructions for connecting to an oracle database?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.