Well i use crystal reports XI R2 but it's the same process to link the .rpt file with the vb6 aplication. I don't remember if in the 8.5 version is necessary, but in the XI R2 you need to have a "developer" license to use it trought visual basic.
There's two ways to do what you want.
- The first one is disigning the report directly trought visual basic, adding the Crystal Reports Designer. I will not explain this method since you are telling that you already have the report disigned in Crystal Report with the corresponding .rpt file. Anyway, this method is for making simple reports since it doesn't bring you as much disign tools as the Crystal Reports aplication.
- The second way (and the better one in my opinion) is designing the report first with the Crystal Reports aplication, and saving the file. Then in Visual Basic you need to add the "Crystal Reports 9 ActiveX Designer Run Time Library" reference and the "Crystal Reports Viewer Control" component.
Add the CRViewer object (used to show the .rpt report file) to a form and use this code:
Variable Declaration:
CODE
Option Explicit
Private crApp As New CRAXDRT.Application
Private crReport As New CRAXDRT.Report
Code in the FormLoad event:
CODE
Private Sub Form_Load()
Dim crParamDefs As CRAXDRT.ParameterFieldDefinitions
Dim crParamDef As CRAXDRT.ParameterFieldDefinition
On Error GoTo ErrHandler
'Opening the report
Screen.MousePointer = vbHourglass
Set crReport = crApp.OpenReport("ReportFilePath.rpt", 1)
' If you want to send parameters to it
Set crParamDefs = crReport.ParameterFields
For Each crParamDef In crParamDefs
Select Case crParamDef.ParameterFieldName
Case "Parametro1"
crParamDef.AddCurrentValue (mstrParametro1)
Case "Parametro2"
crParamDef.AddCurrentValue (mlngParametro2)
End Select
Next
crViewer.ReportSource = crReport
crViewer.DisplayGroupTree = False
crViewer.ViewReport
Screen.MousePointer = vbDefault
Set crParamDefs = Nothing
Set crParamDef = Nothing
Exit Sub
ErrHandler:
If Err.Number = -2147206461 Then
MsgBox "The file doesn't exist", vbCritical + vbOKOnly
Else
MsgBox Err.Description, vbCritical + vbOKOnly
End If
Screen.MousePointer = vbDefault
End Sub
Unload Cleaning
CODE
Private Sub Form_Unload(Cancel As Integer)
Set crReport = Nothing
Set crApp = Nothing
End Sub
So, when you want to show the report by clicking a button, you only have to show this form and that's all.
Note that in the FormLoad event we are opening and sending the data to the .rpt file previously created. In this case i'm sending only parameters type of data, but you can add any other.
Well i hope that this help you at least to begin. Greetings...
This post has been edited by emacrack: 1 Apr, 2009 - 09:03 AM