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.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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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,

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dayikuAuthor Commented:
Actually it seems to be connecting properly.
Do you have the instructions for connecting to an oracle database?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.