PDA

Click to See Complete Forum and Search --> : Extract to CR two recordsets


sacramento
Mar 25th, 2008, 05:37 AM
Hi:

I have this code for extract a recordset to CR:

Set db = Workspaces(0).OpenDatabase(caminho)

Sql = _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2006" & _
" order by nomecomprador"

Set rs = db.OpenRecordset(Sql)
Set Data1.Recordset = rs


Set Report = New CRAXDRT.Application
Set Rpt = Report.OpenReport(App.Path & "\aves2.rpt")

If (Rpt.HasSavedData) Then Rpt.DiscardSavedData

Rpt.Database.SetDataSource rs, 3, 1


setviewersize

CRViewer1.ReportSource = Rpt

CRViewer1.ViewReport


But Now I need to extract annother recordset to the same Report...
Something like this:

Set db = Workspaces(0).OpenDatabase(caminho)

Sql = _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2006" & _
" order by nomecomprador"

Set rs = db.OpenRecordset(Sql)
Set Data1.Recordset = rs


Sql = _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2007" & _
" order by nomecomprador"

Set rs = db.OpenRecordset(Sql)
Set Data1.Recordset = rs



Set Report = New CRAXDRT.Application
Set Rpt = Report.OpenReport(App.Path & "\aves2.rpt")

If (Rpt.HasSavedData) Then Rpt.DiscardSavedData

Rpt.Database.SetDataSource rs, 3


setviewersize

CRViewer1.ReportSource = Rpt

CRViewer1.ViewReport

Off course The report only show one recordset...
Anyone know the way to do this?

Thanks

VBFnewcomer
Mar 26th, 2008, 12:41 AM
Are you trying to display records from two tables

sacramento
Mar 26th, 2008, 12:08 PM
In fact no...this is just a example...But I need make Diferents SQL's from the same table

VBFnewcomer
Mar 27th, 2008, 01:21 AM
In fact no...this is just a example...But I need make Diferents SQL's from the same table hope you are going to retrive the same Fields. Then simply have an IF clause to determine when which SQL to be used.
Set db = Workspaces(0).OpenDatabase(caminho)

If YourCondition then
Sql = _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2006" & _
" order by nomecomprador"
Else
Sql = _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2006" & _
" order by nomecomprador"

End If
Set rs = db.OpenRecordset(Sql)
Set Data1.Recordset = rs


Set Report = New CRAXDRT.Application
Set Rpt = Report.OpenReport(App.Path & "\aves2.rpt")

If (Rpt.HasSavedData) Then Rpt.DiscardSavedData

Rpt.Database.SetDataSource rs, 3, 1


setviewersize

CRViewer1.ReportSource = Rpt

CRViewer1.ViewReport
Have I somewhere lost your main question??!

sacramento
Mar 27th, 2008, 04:37 AM
Hi:

No I don't want a If Else condition...I want Print in the Report the two Sql conditions at the same time in the same report...

VBFnewcomer
Mar 27th, 2008, 05:00 AM
I want Print in the Report the two Sql conditions you mean a set of data satisfying both the SQL statements??
Then simply structure your SQL accordingly.
eg let's assume there is a SQL2 which selects a few sets of records from Table2, Pass this resulting records into SQL1 which further selects/filters based on records from the list by comparing records in Table1.

sacramento
Mar 27th, 2008, 05:24 AM
Sory...but Wicht way I can do this in SQL?

sacramento
Mar 27th, 2008, 08:06 AM
maybe by this way no?:

Sql = _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2006" & _
" order by nomecomprador UNION ALL " & _
"select" & _
" nomecomprador, expositor, gaiola" & _
" from talao2007" & _
" order by nomecomprador"