Solved

Parameter passing in Sub query used in Crystal Reports

Posted on 1998-07-23
1
1,071 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

739 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