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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help! Launch report from VB 6 using RDC?! 1

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hope someone can help...

I have a CR 8.5 report I need to print from a VB program. The report is nearly done (still has some kinks but had to move on to something else, will try more on that later) and I want to use the RDC and or Report Viewer control to show/print the report.

I (think) I need to create and instance of the report in the RDC;
Assign the report file to that object;
Assign three parameters (strings) to it;
pass it to the viewer, or print it directly.

I have tired to follow the documentation in the CRRDC.HLP file and have found that the examples make no sense, that the methods and properties of the controls don't match what I'm seeing. It is very frustrating.

I have a reference set to the "Crystal Reports 8.5 ActiveX Designer Run-time Library", and the "Crystal Report Viewer Control".

Would it be possible for someone to post some sample code, or direct me to a place where I can find better documentation for this? I'm now three days behind on this project and I need to catch up fast.

Thanks in advance for any help anyone can offer.
 
Dim Report As CRAXDRT.Report
Dim App As CRAXDRT.Application

Set App = New CRAXDRT.Application
Set Report = App.OpenReport("your_report_file.rpt")
' connect to the db; many ways to do this
For n = 1 To Report.Database.Tables.Count
Report.Database.Tables(n).SetLogOnInfo "server", "database", "user", "pass"
Next n
' this assumes the viewer is in the same form
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
 
Balves, thanks.

I seem to have gotten through most of this now (at least I figured out how to stop Dr. Watson from killing me), but now as soon as I try to use the ViewReport method of the CRViewer control, I get an error message that says "Server is not yet opened."

What do I do now?

Craig in NJ
 
Following up, I found the following code to set the logon info, which is supposed to make the server not opened error go away:

Rep.Database.Tables(1).SetLogOnInfo "Server", "Table", "User", "Pass"

... But it didn't help. If it matters I'm trying to use a data source from an Oracle database.
 
It's "server", "database" not "server", "table"

For Oracle (which I'm not using right now), the "database" should be the name in your TnsNames.Ora file.
 
Okay, I've set it as you suggested ("Server", "Database", "User", "Pass") but I'm still getting the Server not yet opened message. I wonder if I'm still missing something...

Here's some sample code:

Public Sub PrintDoc(sPONum As String, iPrintStatus As Integer, sCopyName As String)

Dim crxApp As CRAXDRT.Application
Dim crxReport As CRAXDRT.Report
Dim crxParamDefs As CRAXDRT.ParameterFieldDefinitions
Dim crxParamdef As CRAXDRT.ParameterFieldDefinition

Set crxApp = New CRAXDRT.Application

Set crxReport = crxApp.OpenReport(App.Path & "\reports\po03.rpt")
Set crxParamDefs = crxReport.ParameterFields

For Each crxParamdef In crxParamDefs
With crxParamdef
Select Case .ParameterFieldName
Case "PONum"
.SetCurrentValue sPONum
Case "PrintStatus"
.SetCurrentValue CStr(iPrintStatus)
Case "CopyName"
.SetCurrentValue sCopyName
End Select
End With
Next

crxReport.Database.Tables(1).SetLogOnInfo "APPSERVE", "TESTDB", "REPORT", "REPORT"
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport

End Sub

Thanks

Craig in NJ
 
The code is okay. Connecting to the database turns out to be one of the most irritating parts of Crystal. The tek forum is full of "server not opened" threads for different databases.

Are you using an ODBC DSN? If so, you can put that as the first parameter and leave the 2nd parameter blank (""). And an Oracle DSN has to be all caps.

crxReport.Database.Tables(1).SetLogOnInfo "DSN", "", "REPORT", "REPORT"
 
Sadly, no. I'm using the direct connection to Oracle available through the Crystal Interface.

This is really frustrating, why can't I just use the information already stored in the report when I generated it? The report already knows how to connect and read the tables...

Would this be any better/easier if I were to try and pass a recordset fron VB instead of connecting directly to the Oracle DB?
 
I believe that to pass an ADO recordset from VB you must create the report with the Active Data Driver. So you might have to do the report over again.

When you first created the report, what exactly did you pick as the Server type in the little dialog box labelled "Logon Server"?

Was it ODBC - CROR8 or Oracle Server, or something else?
 
I'm fully prepared to re-write the report it I can get it to work. Anything to get this to work I'm running out of time.

When I created the report, these are the selections I made:

Database - Oracle Server (Oracle SQL)
Shows dialog box for logon, asks for User, Pass, Server
This gets me access to selectthe tables I want to work from.

If I were to try and create an ADO Recordset to try and pass to the report (working concurrently) what setup would I need to make that happen?

Thanks

Craig in NJ
 
That server name that you typed in when you created the report has to be in the SetLogonInfo command somehow. I would try either of these:

Rep.Database.Tables(1).SetLogOnInfo "SERVERNAME", "SERVERNAME", "User", "Pass"

Rep.Database.Tables(1).SetLogOnInfo "SERVERNAME", "", "User", "Pass"

You could also try switching the database driver for the report to ODBC - CROR8 (or ODBC - CROR7 if Oracle V7). If you did this, and this is the driver I used on a previous project, then this is what worked for me:

Rep.Database.Tables(1).SetLogOnInfo "CROR8", "DBNAME_IN_TNSNAMESFILE", "User", "Pass"
 
To pass an ADO recordset, you need to pick the Active Data Driver (ADO) as the data source. Then a dialog box comes up and asks for an ODBC connection or OLEDB connection. I would pick CROR8 or CROR7 and go from there. This is the Merant Oracle Driver provided by Crystal.
 
Okay, I created a test report (just a few fields) using the ADO data source. I changed the SetLogOnInfo to direct it at the data source and that works. Now, before I go and rewrite the entire report, is there anything else I should try using the other driver?
 
It doesn't sound as if you're really using an ADO recordset (as opposed to just the ADO Driver). But if it works, that's okay.

If you're really using the ADO driver and an ADO Recordset, you paste the SQL statement into the report (during report creation on the "Select Recordset" dialog box), and then use the function .SetDataSource in VB. In fact, in this scenario you don't use SetLogonInfo at all! There's nothing to "login" to since you're passing the data from VB directly to the report, not telling Crystal that the report should get the data from the Oracle db.

 
With the original report, I would still try a couple of things. Open the report, do a Database / LogonServer, try another driver (like ODBC - CROR8), then do a Database / Set Location to switch the location of the tables over to the other driver, then try the other .SetLogonInfo code:

Rep.Database.Tables(1).SetLogOnInfo "CROR8", "DBNAME_IN_TNSNAMESFILE", "User", "Pass"
 
balves,

Thanks for all your help. I now have a working report and I'm off to other issues. I'll continue to work on it and see if I can get the first method to work eventually, and thanks for the tips on using a SQL query in the report creation. I'll definitely be trying that in the future.

Craig in NJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top