Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh Problem v8.5 using RDC with VB6

Status
Not open for further replies.

MartinDurant

Programmer
Jan 25, 2002
41
0
0
GB
I am calling a report from my VB app using the RDC and the report is displayed before the data is ready despite looping while
Code:
CRViewer1.IsBusy[code] is true. I have to hit the refresh button until the data appears. The relevant bits of code are below:

[b]Print Button[/b]
[code]Set cReport = Appn.OpenReport("f:\vb code\cfs admin\MailLabel.rpt")
frmReportViewer.Show vbModeless

frmReportViewer.form_load
Code:
frmReportViewer.Caption = strReportName
cReport.DiscardSavedData
CRViewer1.ReportSource = cReport
CRViewer1.ViewReport
Label1.Caption = CRViewer1.IsBusy
While CRViewer1.IsBusy
    DoEvents
Wend

CRViewer1.Refresh

What am I doing wrong? Any help greatly appreciated. Thanks.
 
What do you mean the report is displayed before the data is ready? Is it that you don't want the viewer to display without data in it? That's the default Crystal viewer behavior; the viewer will display and if the connection takes a while to return the data, you will see a blank viewer while the data is being returned. However, you might be able to limit this effect by using the following line immediately after the DiscardSavedData call:

cReport.ReadRecords
 
Thanks. I'm not sure it's made much difference, but anything's an improvement. I don't mind that the report displays with no data if the data would appear automatically when it's ready. It annoys me that I (and subsequently my users) will select a report and then have to keep clicking Refresh till the data catches up.

Thanks for your help.
 
I don't understand the need to click refresh. When you do that, you are resending the report's query to the database, which would slow down your app. In fact, the CRViewer1.Refresh call in your code should be unnecessary (and would defeat the purpose of the ReadRecords statement). Nor is the While loop necessary. What kind of performance do you get if you remove those lines? And what is your backend database and what type of connection are you using?
 
I have taken out the refresh and the while loop and performance is unchanged. I am using a local Access database via ADODB. If I don't click the refresh button, the report form is displayed with no data in it. Only when I click the refresh button after a few seconds, does my data appear.

I'm not trying to do anything clever, just create a report from a recordset.
 
Well, something is not right. We'll explore a couple of issues. First, what version of Crystal are you using? Second, what does your record selection formula in the report look like and is it getting passed to the Access database (after running the report in the Crystal Designer, select Database | Show SQL Query and see what is being included in the WHERE clause).

Also, I would suggest downloading one of the sample rdc applications for your version of CR from the Crystal Decisions website. They all pretty much use the Xtreme sample database that comes with CR. While they use an ODBC datasource, you could easily modify them to use OLEDB. Then you could see if you get the same performance issue. If you do, that would be indicative of, most likely, a dll versioning problem. I would suggest making sure you have installed the latest hot fixes for your version of Crystal. You should also verify the version of MDAC you are running and make sure that the MDAC components are all the same version.

You can find the sample RDC apps by searching the CR KB for "sample RDC".
 
I am using Crsytal Reports 8.5, and I downloaded and installed the service pack for this before I started. My record selection formula looks like this:

Code:
SELECT
    rptMailLabel.`MailLabel`
FROM
    `rptMailLabel` rptMailLabel

I am selecting a single field from the table having done all my record selection and pre-processing in VB.

I downloaded the "RDC sample application in VB - Dynamically populating formulas" and that works with no problems. I also downloaded Microsoft's Component Checker and that told me that I was using "MDAC 2.7 RTM".
 
So you actually have no record selection formula in the report itself (there is no WHERE clause in your sql query). How many records are being returned to your report?

Please clarify one other thing. Are you using an OLEDB connection to the Access database or are you passing an ADO recordset from vb at runtime? Your original code posting doesn't indicate that you are using an ADO recordset, but the fact that you are doing pre-processing in VB sounds more like you either are (or should be) using an ADO recordset.

Anyway, if it is not a large recordset (over 10,000 records), I can't see why you would get poor performance. But if you are not using an ADO recordset as the datasource, you should consider it, as it should bypass your connectivity problems to Access.

In summary, what you would do would be create the recordset for the report in vb as an ADO recordset. You would need to design the report to use the Active Data Driver (AD0) and then at runtime pass the ADO recordset to the report. In fact, the sample app you downloaded should show you how to deal with the code to populate the report with an ADO recordset at runtime.
 
I believe I'm using ADO. In VB, I select names from a multi-select list box, match the names with their address and process the address fields into a single string conmtaining the name and address. This is then appended to an empty database table. My mail label report points to this table. The number of records involved is tiny - less than 100!

I can see from the example how to pass the recordset to the report at runtime. I'll read up on the Active Data driver stuff in the CR Knowledge Base and see how I get on.

Thanks for your help
 
I think I've got it sorted! I've had to rebuild my report inside VB, but as it was only mail labels it was not too much work. My other report is more complex and has already taken a considerable amount of time to build. Is there any way to import a .rpt file into the designer in VB?

Thanks for all your help (again)!

Martin
 
Yes, you can import an existing rpt file into the designer in vb.

When you add the Crystal designer to your vb app, you get a "Report Gallery" dialog. On that dialog is an option to create a new report from an existing report. Select that option and then locate the rpt file in the "Open" Browser.

However, you don't need the report to be in a dsr in order to pass it an ado recordset. It may be that that is how the example is created, but if you simply convert your existing report to use the Active Data driver (which doesn't mean you won't have to rebuild some of your report, if it uses multiple tables), you can pass an ado recordset to it at runtime.
 
Thanks. This is all coming together nicely now. I've imported my report, however, it looks as though I have to have one form with a CRViewer control on it for each report. The Report Designer generates a new report display form every time I add a report. Is there a way round this?

 
I guess I was getting lazy there. The obvious solution is to put the Report Viewer on my data selection form and hide it till it's needed. No need for a seperate display form at all then.

Thanks again for all your help.

Martin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top