How can i refresh report values from the database

Posted on 2006-03-27
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.Database.Tables(1).SetLogOnInfo "machinename", "databasename", "userid", "password"
    CRViewer1.DisplayToolbar = True
    CRViewer1.EnableRefreshButton = True

    CRViewer1.ReportSource = Report

I am connecting to an oracle database through an odbc connection
Question by:dayiku
    LVL 1

    Expert Comment

    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.Database.Tables(1).SetLogOnInfo "machinename", "databasename", "userid", "password"

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

    Good luck,


    Author Comment


    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
    LVL 1

    Accepted Solution

    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


    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.

    Author Comment

    Actually it seems to be connecting properly.
    Do you have the instructions for connecting to an oracle database?

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now