Solved

Parameter passing in Sub query used in Crystal Reports

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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