Solved

Parameter passing in Sub query used in Crystal Reports

Posted on 1998-07-23
1
1,070 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

756 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