Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Crystal report using ado
Message
De
02/04/2001 12:16:33
GW Gross
{Banned by Information Security Policy}
Lake Mary, Floride, États-Unis
 
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00488695
Message ID:
00490962
Vues:
13
Eric,

Code is easier to look at then to try and explain, a sample follows. I know it is long, but I included all of the events. This code is in the Form that displays the report to the user. The only control on the form is the CRViewer (crViewBatchDetailReport). crBatchDetailReport is the actual report that was created using the RDC in VB. If you have created you report in the "stand alone" CR then you can import it into the RDC to setup your designer. In the report itself, I use the "ADO Text Only" design and have a TTX file for each of the tables that I am access in the database. Notice that I have an SQL statement that pulls the data from each table and creates a seperate recordset. I then "link" the recordsets with the TTX files with the Database.SetDataSource method.

Hope this helps.

-------------------

Option Explicit

Dim Report As crBatchDetailReport


Private Sub crViewBatchDetailReport_GotFocus()

crViewBatchDetailReport.Zoom (1)

End Sub

Private Sub crViewBatchDetailReport_OnReportSourceError(ByVal errorMsg As String, ByVal errorCode As Long, UseDefault As Boolean)

MsgBox errorMsg & " : " & errorCode & " : " & UseDefault

End Sub

Private Sub Form_Load()

Dim StartDate As String
Dim EndDate As String

'Instantiate Dataset
Call gGetFileLocations
Call gConnectToSpot

'Set CancelReport Flag to False
gbooCancelReport = False

'Get Date Range for Report
StartDate = InputBox("Please enter the start date for the report", _
"Batch Detail Report - Start Date", _
CStr(Date))

'User pressed Cancel, Do Not Proceed
If StartDate = "" Then
gbooCancelReport = True
Exit Sub
End If

If Not IsDate(StartDate) Then
StartDate = CStr(Date)
End If

EndDate = InputBox("Please enter the end date for the report", _
"Batch Detail Report - End Date", _
CStr(Date))

'User pressed Cancel, Do Not Proceed
If EndDate = "" Then
gbooCancelReport = True
Exit Sub
End If

If Not IsDate(EndDate) Then
EndDate = CStr(Date)
End If


'Set MousePointer to "Busy" HourGlass
Screen.MousePointer = vbHourglass

'Display Please Wait Message
Load frmPleaseWait
frmPleaseWait.Show

'Pause for a few seconds to let SPOT Run
Dim PauseTime, Start
PauseTime = 2 'Set pause time
Start = Timer 'Set start time
Do While Timer < Start + PauseTime
DoEvents 'Yield to other processes
Loop

'Open RecordSets
gstrSQL = "Select * From SPOTBatchSummaryStatistics "
gstrSQL = gstrSQL & "Where BatchCreationDate >= #" & StartDate & " 00:00:00 AM# AND "
gstrSQL = gstrSQL & " BatchCreationDate <= #" & EndDate & " 11:59:59 PM# "
gstrSQL = gstrSQL & " Order By BatchID"

grsSPOTBatchSummary.Open gstrSQL, gcnSPOT, adOpenKeyset
Debug.Print "BatchSummary Records "; grsSPOTBatchSummary.RecordCount

gstrSQL = "Select BM.* From SPOTBatchSummaryStatistics as BS "
gstrSQL = gstrSQL & "Left Join BatchModule as BM ON BS.BatchID = BM.ExternalBatchID "
gstrSQL = gstrSQL & "Where BS.BatchCreationDate >= #" & StartDate & " 00:00:00 AM# AND "
gstrSQL = gstrSQL & " BS.BatchCreationDate <= #" & EndDate & " 11:59:59 PM# "
Debug.Print gstrSQL

Debug.Print grsSPOTBatchModule.State
On Error Resume Next
grsSPOTBatchModule.Open gstrSQL, gcnSPOT, adOpenKeyset
Debug.Print "BatchModule Records "; grsSPOTBatch.RecordCount

gstrSQL = "Select * From ModuleLaunch "
grsSPOTModuleLaunch.Open gstrSQL, gcnSPOT, adOpenKeyset


'Instaitate Report Object
Set Report = New crBatchDetailReport

'Connect Report Object to data
Report.DiscardSavedData
Report.Database.SetDataSource grsSPOTBatchModule, 3, 1
Report.Database.SetDataSource grsSPOTBatchSummary, 3, 2
Report.Database.SetDataSource grsSPOTModuleLaunch, 3, 3
Report.Text2.SetText ("For " & CStr(StartDate) & " to " & CStr(EndDate))

'Setup Report Viewer
crViewBatchDetailReport.ReportSource = Report
'MsgBox "Batch Module, 1 " & grsSPOTBatchModule.RecordCount & vbCrLf & _
"BatchSummary, 2 " & grsSPOTBatchSummary.RecordCount & vbCrLf & _
"ModuleLaunch, 3 " & grsSPOTModuleLaunch.RecordCount

crViewBatchDetailReport.ViewReport
While crViewBatchDetailReport.IsBusy
DoEvents
Wend

'Report Complete, close Please Wait message
Unload frmPleaseWait

'Set Zoom to "Page Width"
crViewBatchDetailReport.Zoom (1)

'Maximize the window
frmBatchDetailsReport.WindowState = vbMaximized

Screen.MousePointer = vbDefault

End Sub

Private Sub Form_Resize()

crViewBatchDetailReport.Top = 0
crViewBatchDetailReport.Left = 0
crViewBatchDetailReport.Height = ScaleHeight
crViewBatchDetailReport.Width = ScaleWidth

End Sub

Private Sub Form_Terminate()

'Close connections
Call gCloseSpot

'Release the Report from Memory
Set Report = Nothing

End Sub

Private Sub Form_Unload(Cancel As Integer)

'Close connections
Call gCloseSpot

'Release the Report from Memory
Set Report = Nothing

End Sub
GW Gross

"You are blessed when you're content with just who you are - no more, no less." Matthew 5:5 (The Message)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform