Solved

Parameter passing in Sub query used in Crystal Reports

Posted on 1998-07-23
1
1,045 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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now