Monday, March 12, 2012

Make a Query in VB and pass to CR

Hello all, I'm new to this crystal reports mumbo-jumbo and need some help. Im using VB 6 and the crystal that comes with free with Visual Studio 6. I have to create a report, and I would like to be able to do it from my VB app. I have the user select some criteria from my app. I would then like to construct an SQL query based on that input and output a report. The SQL isnt the problem. I've searched the web for help, but the most help I got was finding out how to install CR and add it to my toolbox.

Where do I go from here? I figure I need to at least layout the report in CR, cause that won't be changing, only the data that goes in the report.

I know I'm asking a lot in this post, but I haven't been able to find answers anywhere else. If one of you gentelmen (or ladies?) could point me in the right direction, I would appreciate it more than you could possibly know.

P.S. I'm using a FoxPro DB if that makes a diffrence. I'm connected with Jet driver.sql query : like only shown record with lastname = erick?
if it is u could use selection formula..

cRt.selectionformula = " lastname = '" & text1.text & "'"

regards|||Thats kind of what I'm looking for. What I have is a table that has some test information, test id, name, number of questions, etc. Then i have a test taker table that has all the ususal info, ie, name, ssn, ... and also the test they took. what I want to do is populate my report with only the test takers who scored above a certain number, who took the selected test. I know how to structure the query, but I don't know what to do with it once I have it. I saw there is a sqlquery property so i set it equal to my query, then showed my report, but nothing happend.|||cRt.selectionformula = " lastname = '" & text1.text & "'"

is "lastname" a field in the report?|||I tried something similar to what just got posted but nothing happend, my report didn't even print to the screen. I think that that might just add 1 record to the report, would I have to loop through an entire recordset to populate the report, or is there another way?|||There are 2 ways (that I know of) that you can do your query and get the results within VB, then pass only the data to Crystal Reports.

The first way is use ADO or RDO and pass the recordset to the report.

The second way is to use CDO (Crystal Data Objects) to pass the data to the report. With CDO, you populate an array with your data and stuff the array into a CDO Rowset (which is similar to an RDO resultset or an ADO Recordset).

Using either of these 2 methods, the only Crystal does is display the data.

For more info on CDO, see this link (http://www.dev-archive.com/forum/showthread.php?s=&threadid=281658&highlight=cdo)

Also, have a look at this (http://www.dev-archive.com/forum/showthread.php?t=298564&highlight=rdc). It gives code on 2 different ways of passing the data to the report. (rsData would be an ADO recordset since that's what I use, but you can replace that with an RDO resultset or a CDO rowset)

I personally prefer to use CDO and the second method from the second post (called RDC), since it seems to give you more control (ie, with RDC you can move fields and rename column headers, etc, that are in the report.)

One last thing, keep in mind that I use Crystal Reports 8.5, so if you have a different version, you may not be able to use the code I have posted word-for-word.

And check out Crystal's Support Website (http://support.businessobjects.com/search/advsearch.asp) and Crystal's Suport Forum (http://support.businessobjects.com/forums/default.asp)|||is "lastname" a field in the report?
yes it is..that is the field that user want to retrieve..
text1.text is the value that user choose..is this case
filed (lastname) with value = erick
cRt is ur crystal report control name

would I have to loop through an entire recordset to populate the report, or is there another way?
u don't have to loop entire record..if the value that user enter is in the table then the report will shown..the other way maybe what malleyo do..right now i'm using the method above..

regards

No comments:

Post a Comment