TIP: Click on subject to list as thread! ANSI
echo: visual_basic
to: All
from: Miles Thompson
date: 2004-07-20 21:33:00
subject: Re: CR subreport queries

Jennifer wrote:

> Hello,
> 
> I am attempting to relay an SQL query to a report designed with
> Crystal Reports from the Visual Basic environment.  The report I
> designed in CR has subreports embedded within the main report.  I have
> been able to write a query which changes the main report (see below),
> but I am unable to find a way to write a similar query to update
> information in the subreports.  What is the correct way to do this?
> 
> Private Sub Form_Load()
> 
> Screen.MousePointer = vbHourglass
> Set Report = Application.OpenReport("C:\Sample Report.rpt")
> Report.DiscardSavedData
> 
> Dim strSQLFilter As String
> 
> strSQLFilter = "Scenario 1"
> 
> Report.SQLQueryString = _
>    "`Table1`.`Field1`, `Table1`.`Field2`, FROM `Table1` WHERE
> `Table1`.`Field1`='" & strSQLFilter & "'"
> 
> ' -- HOW DO I SET THE QUERIES FOR ALL OF THE SUBREPORTS? -- '
> 
> CRViewer1.ReportSource = Report
> CRViewer1.ViewReport
> Screen.MousePointer = vbDefault
> 
> End Sub

I'm not setting queries, but do have to tell several subreports where the
tables are, like so

....
'
' tell the subreports where the database is
'
Set crxSubreport = Report.OpenSubreport("HazMaterials")
For Each crxDatabaseTable In crxSubreport.Database.Tables
    crxDatabaseTable.Location = sPathFPPM
Next crxDatabaseTable

Set crxSubreport = Report.OpenSubreport("Accessibility")
For Each crxDatabaseTable In crxSubreport.Database.Tables
    crxDatabaseTable.Location = sPathFPPM
Next crxDatabaseTable
..... and so on. 

So why not, set the crxSubReport, as above, and then do
crxSubReport.SQLQueryString =  "`Table1`.`Field1`, `Table1`.`Field2`,
FROM `Table1` WHERE `Table1`.`Field1`='" & strSQLFilter &
"'"

Hoe this is helpful - CR can be damnably confusing, and sometimes the
solutions are so simple. Othertimes, not so.

Cheers - Miles Thompson
---
þ RIMEGate(tm)/RGXPost V1.14 at BBSWORLD * Info{at}bbsworld.com

---
 * RIMEGate(tm)V10.2áÿ* RelayNet(tm) NNTP Gateway * MoonDog BBS
 * RgateImp.MoonDog.BBS at 7/20/04 9:33:32 PM
* Origin: MoonDog BBS, Brooklyn,NY, 718 692-2498, 1:278/230 (1:278/230)
SEEN-BY: 633/267 270
@PATH: 278/230 10/345 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.