Solved

Parameter passing in Sub query used in Crystal Reports

Posted on 1998-07-23
1
1,054 Views
Last Modified: 2012-06-27
Can Parameters or formulas be passed to a subquery used in Crystal Reports from VB.
For example look at this query shown by Crystal Report "Show SQL Query" option
  Select a.field1,b.field2 from a,b where a.field1 = b.field1 and a.field2 not in (select c.field1 from c where c.field1 = <formula>)
  Here we are not able to insert a formula in Crystal Report Designer.
   We created a Stored Procedure with a parameter in sub query and tried to use this stored procedure in Crystal Report to design a report, but during design time of the report itself, the parameter value is accepted and stored along with the report. So we are not able to change this parameter value during runtime from VB.
  Is there any other way we can pass a parameter or formula to a sub query from VB to CR?
  We are using VB5.0,MS-SQL Server 6.5, Crystal Report 6.0
0
Comment
Question by:vvg
1 Comment
 
LVL 3

Accepted Solution

by:
dapperry earned 50 total points
ID: 1466575
I am only a newbie-Expert, but if I were you I would place a Crystal Report control on one of your forms, and place a data control on the form as well.  You would then need to  set the DataSource property of the CrystalReport control to: the name of your data control, eg data1
Then set the ReportSource to: 3-crptDataControl.  Also fill in the ReportFileName property to equal: the path and filename of your crystal report, eg c:\myreport\cool.rpt  .  As for the data control, you will leave all properties alone, except for the name.

Now you can create a recordset based on the query.  If you were having the user input the formula, leave them a text box (txtuserinput) to enter it in, and place a command button on the form.  In the
onClick event of the command button place similar code.

dim db as database
dim rst as recordset
dim qdf as querydef
dim sqlstring as string

set db=opendatabase( "c:\mydb\test.mdb)

'Now create the SQL string by concatenating user input with rest of SQL statement
sqlstring=" Select a.field1,b.field2 from a,b where a.field1 = b.field1 and a.field2 not in
   (select c.field1 from c where c.field1 = "+txtuserinput+")"

'Now create temp querydef
set qdf=db.createquerydef("",sqlstring)

'Now get recordset of query
set rst=qdf.openrecordset(dbopendynaset) 'or dbopensnapshot

'Now assign this recordset to the recordset of the data control
set data1.recordset = rst

'Now you can run the crystal report based on the recordset in the data control
crystalreport1.printreport


Let me know if this code works for you, or needs greater clarification.

:) D Perry
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now