How to Pass Parameters into CR

ManojP
ManojP used Ask the Experts™
on
Hi Friends,

I'm developing an application with VB+SS7 and using CrystalReports 8.5 for Reporting. I created StoredProcedures with Prameters and I use these SPs for my Report. I have a common form in VB which will accept the parameter for all my CR. When the user enter the information in first form and click okay, it will display another form which contain CRViewer. Below is my code. After I run my report, it generate 2 errors.
1. Server has not yet been opened. (But when I run the report form CR, it works fine.)
2. The value/Range you are adding has already existed

Below is my code from VB. Please help me to resolve this issue.
                crxApplication.LogOnServer "p2sodbc.dll", "SOFT2", "famDB", "ancyjohn", "harpin"
Set crxReport = crxApplication.OpenReport("D:\Program Files\Microsoft Visual Studio\VB98\final\rpTest.rpt")
crxReport.ParameterFields.Item(1).AddCurrentValue (""" & Left(cboReport, 1) & """)
crxReport.ParameterFields.Item(2).AddCurrentValue (""" & mskFromDt.Text & """)
crxReport.ParameterFields.Item(3).AddCurrentValue (""" & mskToDt.Text & """)
frmViewerForm.CRViewer1.ReportSource = crxReport
frmViewerForm.Show

Thanks & Regards
Manoj
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Manoj
Try to convert database driver of crystal report from p2odbc.dll to p2ssql.dll. (In crystal reports Menu, go to database menu item and from the drop down menu item select convert database driver..

If you have built the report with one mechanism and trying to log on with other type of mechanism, then you will be getting error "server has not yet opened".
if you are familiar with crystal ocx then it is more easy to write front end code.

HTH
VG
Do not switch to the SQL native driver (p2ssql.dll), Seagate/Crystal Decisions recommends that you do not use this driver.  Instead use ODBC (as you do) or OLE DB would be even better.

However changing drivers is not something that relates to you issue.

The reason you are receiving the error 'Server not yet openned' seems to be because you are not providing the report with a datasource.

Try taking a look at 'Data Source' in the developer's helpfile.  I don't have the file or some sample code here.

Or see if you have mispelled your report declaration:

**From the Crystal Decisions Web Site ***

This error appears because the report object was declared incorrectly as:

Dim report as CRAXDDRT.Report

To resolve this error message, declare the report object as:

Dim report as CRAXDRT.Report

Note: =======

Craxddrt.dll is used to create reports at runtime while craxdrt.dll is used to view and alter existing reports.

Author

Commented:
Hi gvgs98 & gawilson2000

Thanks for your quick respond. I notice one thing that the above mentioned problem has only arise when I try to run a parameter based report. For a non-parameter report, it works fine. I have a stored procedure in my SS7 DB, which will accept two parameters on both Date Datatype

1. From date 2. To date

Now When I create report through the report wizar, it ask me for the parameter value. I don't know how to skip this. For the time begin, I enter fake values and from the Design View, I clear the values. When I run the report from CR, it gives me the exact result. Now I would like to accept the parameter values from the user through my application instead of CR parameter value prompt. So I use crReport.EnableParameterPrompt = False. When I try to pass my own parameter from VB app., the above mentinoed error generates. Is this much info is enough to solve my problem.

Pls guide me, how to create a Parameter based report.

Thanks & Regards
Manoj
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Lets say you have 2 fields in your VB app thru which u are passing the data parameters : txtDate1 and txtDate2

In you code write the following command :

report.parameterfields.item(1).addcurrentvalue =
txtdate1.text

report.parameterfields.item(2).addcurrentvalue = txtdate2.text

Try it
Manoj

Pl. ignore my comment. It was send to u by mistake.

Author

Commented:
Hi gawilson2000

Thanks for your link, which help me to solve my problem. Also I got adequete knowledge about passing parameters. I recreate my crystal report which connect to my db through a DSN. Last time I use the option of MoreDatabase option while connecting to server. Also thanks to rituarora & gvgs98.

Thanks & Regards
Manoj
Glad to be able to help.

Please 'accept' someone's comment as the answer to allocate the points.

Author

Commented:
Hi gawilson,

I have one more question to ask. How can I print the crystalreport file directly to the printer without viewing it. When I try CRViewer1.PrintReport, nothing comes out.

Thanks
Manoj
I have not played with VB for a long time.

It used to be the case that you would set the 'Action' property to a different value for straight to printer.

Are you using this property?

Is there not a destination property?  Does the developer help file help?
I just found this code, it may help:

    CrystalReport.Destination = crpToPrinter
Write the following statement :

report.printout = false

It would print the report without prompting the user
How have you gone with this?

Author

Commented:
Yes gawilson2000

I got it, thanks for your kind help. All the best.

Regards
Manoj
ManojP,

Welcome to Experts-Exchange! I was alerted by an expert that you have not close any of your open questions here on the site. Realizing you are probably new and don't understand the way the site works I thought I would brief you on it.

Questions here are handled a little different than most forums. Here we use a system of asking/closing questions. When you close a question you are telling the expert that helped you that you really appreciated their help and are giving them what we call Expert points for an appreciation.

Along with expert points you give them a grade. The higher the grade you give them when you close the question the better chance they will help you next time.

To accept an answer click on the link above the expert's comment that helped you entitled "Accept Comment as Answer" then assign a grade and click Submit. That will close the question.

With a lot of open questions experts won't likely help you with issues because they will think you are just running with the question and not rewarding them for their help. For this reason we ask that you please take care of your open list of questions before they end up on our abandoned list of questions. Thank you for your contribution and support to Experts-Exchange!

DigitalXtreme
CS Moderator
This question has been classified abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I appreciate any comments that would help me to make a recommendation.


Unless it is clear to me that the question has been answered I will recommend delete. It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.


If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

Pat K
EE Cleanup Volunteer
I believe it to be clear that I answered the initial question plus a follow up question.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: gawilson2000 {http:#7460454}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

mnye
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial