Crystal report data not refreshing

kbrochu
12-17-2003, 08:57 PM
Hello,
I am trying to write a VB 5.0 program with Crystal 8.5 that looks at Oracle 8.05 data. I would like for the report to use a new recordset as data, rather than the original recordset that was used when the report was created. The following code runs, but continues to return the same data as when the report was created. Your help is much appreciated...here is the code.




Dim appl As New CRAXDRT.Application
Dim rep As New CRAXDRT.Report
Dim AdoRs As New ADODB.Recordset



AdoRs.Open "Select subjects.* from subjects where jid = " & 30, "Driver={Oracle ODBC Driver};" & _
"Dbq=Name;" & _
"Uid=User;" & _
"Pwd=PSW"
Set rep = appl.OpenReport("d:\ivrs\crystalreports\subjects2.rpt", 1)


rep.Database.SetDataSource AdoRs
rep.ExportOptions.DiskFileName = "c:\TestExport15.doc"
rep.ExportOptions.DestinationType = crEDTDiskFile 'or use crEDTDiskFile
rep.ExportOptions.FormatType = crEFTWordForWindows 'format changes for .rft, word, PDF, etc
rep.Export False
rep.SaveAs "d:\ivrs\crystalreports\subjects15.rpt", cr80FileFormat

AdoRs.Close
Set AdoRs = Nothing
Set rep = Nothing
Set appl = Nothing
End Sub

bvmantos
12-17-2003, 09:26 PM
You may try to set discarddata property to True before passing the recordset to it. maybe it would solve it.

mikechan8888
12-17-2003, 10:54 PM
You may try to set discarddata property to True before passing the recordset to it. maybe it would solve it.
You mean the .DiscardSavedData method?

Mike

bvmantos
12-17-2003, 11:06 PM
Yes! im not sure though. BUt maybe it would reset the data. Well, i seldom use that method since my report works so fine.

mikechan8888
12-18-2003, 02:46 AM
Yes! im not sure though. BUt maybe it would reset the data. Well, i seldom use that method since my report works so fine.
I understand! I rarely need to use the DiscardSavedData method. But I did experience a couple times when I couldn't get the current data from my report and I followed exactly the same practice I always used. Then I emailed CR support for help and they told me to use this method. It worked after that.

All they told me was "you should always call this method before you call other methods or set other properties."...but as to why...nobody told me...yet... :rolleyes:

It still seems to me as a "random error" (but I am sure it is not), but just for safety, I always use this method now... :p

Mike

MKoslof
12-18-2003, 06:39 AM
*typically* .rpt files natively save data with the report..sometimes even when you uncheck the "save data with report" on the rpt file itself. The DisgardSavedData method was built to help clean out existing recordsets.

This method typically does the job, but another neat trick is to create a new report object and initially set it to nothing and then rebuild it..this forces an initial clean build....

Optikal
12-18-2003, 07:50 AM
The method I use, is instead of creating a report with data, I just give it a .ttx file which specifies the structure of the recordset (but not actual data). Then I just pass it a recordset which matches the ttx file at runtime. Never have I had to use .DiscardSavedData.

kbrochu
12-18-2003, 07:57 AM
When I add rep.DiscardSavedData to the code, I now get the error:
"Server has not yet been opened"....

bvmantos
12-18-2003, 10:22 PM
When I add rep.DiscardSavedData to the code, I now get the error:
"Server has not yet been opened"....Where did u put this line? You should put this code after OpenReport method.

MKoslof
12-19-2003, 06:17 AM
you mentioned earlier that this error has occured randomly before, "Server not yet opened" is a connection issue...really has nothing to do with the .disgarddata method.

For ODBC you should use the setlogonInfo method of th method of the Report.Database.Tables method call. Use a For loop and loop all the tables within the report and connect:

These are all found within the CRAXDRT object: the references are available within your VB project file



For each crxTable in myReport.Database.Tables
crxTable.setlogoninfo serverName, dbName, dbUser, dbPassword
Next



I say this because it appears you are using ADO (with the SetDatasource method) and an ODBC connection. Some people say for native connections, to use the logonserver method, but I have never been a fan of it. I tend to always use the Active Data driver for all my CR Reporting.

And yes, you should put the disgardsavedData call after opening your report and binding your connection.

AndyJ
12-19-2003, 07:45 AM
Hi,

Sometimes I use a local database as a sort of dataholder for the report whilst I design it. I create an Access DB with tables I need. Then I go into Crystal, set the datasource to my local database - not various other DBs the data actually comes from and setup my report.

Each report has a database. This database is made of tables. Each table has a location. You can chop and change the location of these tables programatically in VB b4 the report is opened.

The following code alters the locations of 2 tables. Table(1) I want to look at a secure Access database, so I set the connectionbufferstring segments to various variables I have (like database location, username, password and securityfilelocation). I then test the connectivity of that table.

The second table to be modifed will be populated with a recordset that I've got open already called mrsSource - note the setprivatedata. Also note that the recordset must be the same structure as the one used when creating the report. Thats why I sometimes make an access DB to simulate what structures the report will be given at runtime (mrsSource is just a query at runtime, but when the report was written I created a table to mimik the recrodset).


rptCurrent.Database.Tables(1).ConnectBufferString = _
"Database Name=" & gSettings.DatabaseFile & ";;" & _
"Database Type=Access;;" & _
"Database Password=;;" & _
"Session UserID=" & gsUsername & ";;" & _
"Session Password=" & gsPassword & ";;" & _
"System Database Path=" & gSettings.SecurityFile

If Not rptCurrent.Database.Tables(1).TestConnectivity Then

Err.Raise 1, , "Unable to connect to " & rptCurrent.Database.Tables(1).Name & _
" for " & gsUsername & "." & vbCrLf & vbCrLf

End If

'Next iCount

rptCurrent.Database.Tables(3).SetPrivateData 3, mrsSource



Hope some of that helps.

Good luck,
Andy

Hello,
I am trying to write a VB 5.0 program with Crystal 8.5 that looks at Oracle 8.05 data. I would like for the report to use a new recordset as data, rather than the original recordset that was used when the report was created. The following code runs, but continues to return the same data as when the report was created. Your help is much appreciated...here is the code.




Dim appl As New CRAXDRT.Application
Dim rep As New CRAXDRT.Report
Dim AdoRs As New ADODB.Recordset



AdoRs.Open "Select subjects.* from subjects where jid = " & 30, "Driver={Oracle ODBC Driver};" & _
"Dbq=Name;" & _
"Uid=User;" & _
"Pwd=PSW"
Set rep = appl.OpenReport("d:\ivrs\crystalreports\subjects2.rpt", 1)


rep.Database.SetDataSource AdoRs
rep.ExportOptions.DiskFileName = "c:\TestExport15.doc"
rep.ExportOptions.DestinationType = crEDTDiskFile 'or use crEDTDiskFile
rep.ExportOptions.FormatType = crEFTWordForWindows 'format changes for .rft, word, PDF, etc
rep.Export False
rep.SaveAs "d:\ivrs\crystalreports\subjects15.rpt", cr80FileFormat

AdoRs.Close
Set AdoRs = Nothing
Set rep = Nothing
Set appl = Nothing
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum