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!

Crystal Dies, cannot pass parameter, .parameterfields isn't an option

Status
Not open for further replies.

jenlion

IS-IT--Management
Nov 13, 2001
215
I could really use some help getting my crystal report to run from my VB app. I have two problems:

1. If rept is my crystal report, I have several choices in properties and methods: rept.printreport, rept.sqlstring, etc. I want to pass a parameter to my report, though, and all the examples show rept.ParameterFields(x). I don't have ParameterFields as an option. I'm able to change the SQL string to reflect what I need, but that's not a scalable solution.

Is there some reason I don't have ParameterFields as an option? I get an error if I try to use it anyway (object doesn't support this method).

2. If my report gets too complicated, it will not open. I can say rept.PrintReport, and a Crystal window flashes and closes. Nothing. This happens sometimes when I add fields from tables to my report. I am not prompted to log on; I do have a connection to the SQL server database from the vb program, but the report doesn't ask me to make an OLE or ODBC connection (I've tried both). It just dies. No explanation. I've tried setting rept.UserName and rept.Password, but it doesn't seem to care.

I'm using VB6 sp5 and Crystal Reports 8 Professional. I found that I had to run the crystal reports installation that was included with Visual Studio 6 in order to get the Crystal Reports availablitiy in VB6; I installed to a different location from, but in addition to, my CR8. Crystal 8 doesn't seem to have a problem with that.

If anyone can give me some ideas, I would appreciate it. I've scoured everything, and everyone else seems to have this rept.ParameterFields(x) available. Hmm.
 
Unfortunately, you should have bought Crystal Developer, not Crystal Professional, to integrate with VB. Starting with V8, Crystal needlessly confused people by separating Crystal Reports into 3 separate products: Standard, Professional and Developer.

The Crystal that comes on the VB 6 disk is Crystal V4.6. Depending upon your needs, it might be good enough to do what you want to do.
 
Thanks balves.

OK, I have obtained Crystal Developer. Now I have new questions.

I might want to say that rept.ParameterFields(0) = 287, with the only parameter field in my report requesting a number, but VB tells me at run that "subscript is out of range". I've tried 287, "287", and some other things. Ultimately this will need to be a variable but I can't even get it to accept a constant!

I need to establish a connection to the SQL server for my report. How do I do this? rept.connect? If so, can someone help me with the syntax there? I don't care if it's ADO or ODBC or what, I can do any of it.

Syntax to print the report would help me too. I've come across a way of doing it, but it involves defining some craxdrt applications and reports, and I'm not sure what I'm doing there.

Thanks for any help; I can't seem to find any simple documentation for what I'm sure is a simple problem: open my report, accept a parameter, and print the stupid thing!

Thanks.
 
If you did a complete install, there's a sub-directory of the Crystal Reports software directory with a bunch of VB examples.

First, you have to choose an integration method:

1. The old way. Drop the CrystalReport OCX from the VB toolbox onto a VB form (after adding the references in VB via Project / Components. In this case, you use CrystalReport1.Connect = "..." to connect to the db.

2. The new way. The RDC. You can create reports inside of the VB environment and they end up inside the VB .exe or continue to build reports with the separate Crystal Report designer. In this case, you have statements like this in your VB code:

Dim CRXApp as CRAXDRT.Application
Dim CRXReport As CRAXDRT.Report

In this case, you use .LogonServer or .SetLogonInfo to connect to the db.

3. Use an ADO recordset. In this case, you use the Active Data Driver (ADO) when choosing the data source during the report creation. Later, in VB, you open a recordset and just pass the recordset to the report. No need to connect to the database.
 
The line:

rept.ParameterFields(0) = 287

won't be valid in any integration method. If you are using the OCX you would need something like:

rept.ParameterFields(0) = "paramName;287;True"

There are 4 different sets of CR syntax, and we have to know which one you are using. See faq149-237 for more info. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thanks for the input.

I chose to use the RDC and thought that I had things working. I was using OLEDB to my SQL server, but discovered the little bug Crystal has in that. I switched the report to ODBC and changed the dll reference to odbc as well, but something isn't right.

I managed to open the report with the RDC and pass the paramter with addcurrentvalue. Everything seemed to work fine with

Report.Database.LogOnServer "pdsodbc.dll", "servername", "database", "username", "password"

for awhile. I compiled, distributed, and installed the finished program, which works fine on my machine. Unfortunately, it does not work on the end user's machine, and suddenly, even the code has not been modified, does not work when run from VB, either. I get the apparently common "server has not yet been opened" message when I reach the line for logonserver. I've tried report.database.tables(1).setlogoninfo, but that doesn't work either -- I print a blank piece of paper.

Report.database.logonserver "pdsodbc.dll", "dsn", "database", "username", "password" gets me the report printed with no information.

Opening the report in Crystal works just fine.

I can't seem to find the correct way to connect to my sql server and *then* send the parameter to my report for printing. I've found the bug in OLE with pdsoledb, but their workaround doesn't seem to work for me. Does anyone have a working solution??

Thanks.
 
You're not connecting successfully to the database from VB.

Report.database.logonserver "pdsodbc.dll", "dsn", "database", "username", "password"

Don't use "pdsodbc.dll" - that's the old 16-bit DLL. Use "p2sodbc.dll".

The "dsn" is case-sensitive. Make sure that the DSN on the client's PC matches the VB code case-wise. If you are using a DSN, leave the next parameter blank as in:

Report.database.logonserver "p2sodbc.dll", "dsn", , "username", "password"

Also make sure that the client PC has a relatively recent version of the Microsoft MDAC kit. Check the version of the SQL Server ODBC driver in Control / Panel / Data Sources.
 
I had tried p2sodbc and it hadn't worked either. Some documentation (old!) that I found didn't mention it, so I went to pdsodbc. Guess I'll be changing that; thanks for your input.

I did finally get it to work, and here, in case anyone reads this thread for help later, was the problem: DLL registration.

I had used Crystal Professional, the standalone Report Designer Component, AND Crystal Developer. (Yes, I uninstalled professional before installing developer, and developer is a later version than the RDC, but the dlls did not copy over). The correct craxdrt, craxddrt, and craxddt.dll have to be RE-registered with regsvr32 (command prompt: c:\winnt\system> regsvr32 "craxddt.dll").

Hope this saves someone else from a similar bout of serious frustration.

 
using VB 6 and crystal 8
line :

CrystalReport1.ParameterFields(0) = "DateDebut ; DateHeure (2002,01,28,00,00,00) ;true"

Without this line, it works perfectly but users have to enter parameters using crystalreport prompt .
With this line, it just doesn't work. Neither error message, nor results (Normaly, it saves results to a .rpt file) .

You once wrote that there was 4 different synthaxes ... could you give them to me, or tell me what's wrong in my code ?
 
actually, my problem just deals with the date ... cause I managed to pass string parameters .
And I'm worry a little , cause I've tried lots of things which don't work :

CrystalReport1.ParameterFields(0) = "DateDebut ; DateHeure (2002,01,28,00,00,00) ;true"
CrystalReport1.ParameterFields(0) = "DateDebut ; DateTime (2002,01,28,00,00,00) ;true"
CrystalReport1.ParameterFields(0) = "DateDebut ; CDateTime (#9/10/92#) ;true" etc.....

SOS
 
Is the report against a stored procedure?
Which integration method are you using? faq149-237 Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
the report is not against a stored procedure and I use OCX .
I 've been loocking for forums telling about this problem, and I start worrying a little ... cause I'm sure I do exactly what I'm suppose to . I hope you'll be able to help, and , anyway, thank you for answering so quickly.
 
What is the record selection formula of the report? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
euh... record selection formula ? well, if I right click on a field in the .rpt field, and do expert selection, there is something like that : {R6100401.StartDateTime}<= {?DateFin} and {R6100401.StartDateTime}>= {?DateDebut}

Does it corresponds to what you mean by selection formula ?
 
Are you passing both parameters from the code or just one? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Actually, I pass 3 parameters from the code . Usine, corresponding to {?Usine} . This one works very well. And the two dates : DateDebut and DateFin corresponding to {?DateDebut} and {?DateFin}
 
Post the 3 lines of code you are trying for passing the three parameters. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top