
VB6 and CR 8.5 integration
Once u a using the viewer, there are different ways to call the report. This
is the way I did:
1.Create a form with the crviewer control
2. create some global variables or call the form with parameters of which
report to print
here is some a sample of the code the the report.frm file
Private Sub Form_Activate()
' On Error GoTo ReportError
On Error Resume Next
Set lRdApp = CreateObject("CrystalRuntime.Application")
Set Report = lRdApp.OpenReport(gReportTemplate)
For i = 1 To Report.Database.Tables.Count
Set crpTable = Report.Database.Tables.Item(i)
crpTable.SetLogOnInfo gServerName, gDatabaseName, "sa", ""
Next i
Set crpParamDefs = Report.ParameterFields
Screen.MousePointer = vbHourglass
If gstrSQL <> "" Then
Report.SQLQueryString = gstrSQL
ElseIf gSelectionFormula <> "" Then
Report.RecordSelectionFormula = gSelectionFormula
End If
If gParameters <> "" Then
For Each crpParamDef In crpParamDefs
With crpParamDef
Select Case .ParameterFieldName
Case "TotalMonths"
.SetCurrentValue (gParameters)
Case "StatementDate"
.SetCurrentValue (CDate(gParameters))
Case "datesent"
.SetCurrentValue (CDate(gParameters))
Case "Custnum"
.SetCurrentValue (gClientCode)
Case "DateSelect"
.SetCurrentValue (CDate(gParameters))
Case "AddPrem"
.SetCurrentValue CDbl(gParameters)
End Select
End With
Next
End If
CRViewer1.ReportSource = Report
'Suppress detail line
Report.Sections("D").Suppress = gSuppressD
Report.ReportTitle = gReportTitle
Report.UseIndexForSpeed = True
Report.VerifyOnEveryPrint = True
'Report.PaperSource = crPRBinEnvelope
Screen.MousePointer = vbDefault
If gReportPrintNow = False Then
Me.Caption = gReportTemplate
CRViewer1.ViewReport
Else
Report.PrintOut False, 1, False, 1
Unload Me
End If
gSelectionFormula = ""
gReportTemplate = ""
gReportTitle = ""
gParameters = ""
gSearchTitle = ""
gReportPrintNow = False
'//*** ERROR-STUB ADDED BY ADD-IN
Exit Sub
ReportError:
MsgBox "[" & Err.Number & "] " & Err.Description, vbInformation,
"Form_Load - Error"
Resume Next
End Sub
'//***
************************************************************************
Private Sub Form_Load()
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
gReportTemplate = ""
Set crpTables = Nothing
Set crpTable = Nothing
Set crpParamDefs = Nothing
Set crpParamDef = Nothing
Set lSections = Nothing
Set Report = Nothing
gSuppressD = False
Set lRdApp = Nothing
' lRdApp.LogOffServer "p2ssql.dll", "SERVERNAME", "Databasename",
"sa", ""
Set frmReport = Nothing
End Sub
Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub
hopefully this helps
Vincent