What i cant figure out is how to call the report from within vb6 when a button is clicked. ANyone help with this?
Thanks in Advacne
This post has been edited by kajirus3: 31 March 2009 - 09:24 AM
|
|
|
|
VB6 and crystal reports 8.5
Page 1 of 1
VB6 and crystal reports 8.5 need help with these 2 working together#1
I have a report named control_record.rpt that does everything i want in crystal reports 8.5. It prints all the records.
What i cant figure out is how to call the report from within vb6 when a button is clicked. ANyone help with this? Thanks in Advacne This post has been edited by kajirus3: 31 March 2009 - 09:24 AM #2Posted 01 April 2009 - 09:00 AM
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: Option Explicit Private crApp As New CRAXDRT.Application Private crReport As New CRAXDRT.Report Code in the FormLoad event:
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 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: 01 April 2009 - 09:03 AM #3Posted 08 April 2009 - 05:12 AM
I have a report named control_record.rpt that does everything i want in crystal reports 8.5. It prints all the records. What i cant figure out is how to call the report from within vb6 when a button is clicked. ANyone help with this? Thanks in Advacne
I am passing a custom SQL query as well as just passing parameters will not always get the job done
Dim sql As String
Dim yBeginDate As String
Dim yEndDate As String
'clear out old data
Me.CrystalReport1.DiscardSavedData = True
Me.CrystalReport1.Reset
'get the start and stop date for the report
GetDates Trim(Str(Me.cboMonth.ListIndex + 1)), Trim(Me.cboYear.Text)
sql = "({AuditTable.AuditDate} >= DateTime("
sql = sql + Str(Year(dtStartDate))
sql = sql + "," & Month(dtStartDate)
sql = sql + "," & Day(dtStartDate)
sql = sql + "," & Hour(dtStartDate)
sql = sql + "," & Minute(dtStartDate)
sql = sql + "," & Second(dtStartDate) & "))"
sql = sql + " AND ({AuditTable.AuditDate} <= DateTime("
sql = sql + Str(Year(dtEndDate))
sql = sql + "," & Month(dtEndDate)
sql = sql + "," & Day(dtEndDate)
sql = sql + "," & Hour(dtEndDate)
sql = sql + "," & Minute(dtEndDate)
sql = sql + "," & Second(dtEndDate) & "))"
'reset all good params
Me.CrystalReport1.SelectionFormula = sql
Me.CrystalReport1.ReportFileName = "report name.rpt"
Me.CrystalReport1.Connect = "uid=xxxx;pwd=xxxx;"
Me.CrystalReport1.PrintFileType = crptRecord
Me.CrystalReport1.ReportSource = crptReport
Me.CrystalReport1.ReportTitle = "Audit Report - Deleted Entries"
Me.CrystalReport1.WindowTitle = "Reports: Audit Report - Deleted Entries"
yBeginDate = "DateTime(" & Year(dtStartDate) & "," & Month(dtStartDate) & "," & Day(dtStartDate) & "," & Hour(dtStartDate) & "," & Minute(dtStartDate) & "," & Second(dtStartDate) & ")"
yEndDate = "DateTime(" & Year(dtEndDate) & "," & Month(dtEndDate) & "," & Day(dtEndDate) & "," & Hour(dtEndDate) & "," & Minute(dtEndDate) & "," & Second(dtEndDate) & ")"
Me.CrystalReport1.Formulas(0) = "startDate = " & yBeginDate
Me.CrystalReport1.Formulas(1) = "endDate = " & yEndDate
'launch the report
Me.CrystalReport1.WindowState = crptMaximized
Me.CrystalReport1.Action = 1
Page 1 of 1
Fast Reply
1 User(s) are reading this topic
|
||||||||
Forum Index:
Programming Help |
C and C++ |
VB6 |
Java |
VB.NET |
C# |
ASP.NET |
PHP |
ColdFusion |
Perl and Python |
Ruby |
Databases |
Other Languages |
Game Programming |
Mobile Development |
Software Development |
Computer Science |
Industry News |
52 Weeks Of Code |
Programming Tutorials |
C++ Tutorials |
Visual Basic Tutorials |
Java Tutorials |
VB.NET Tutorials |
C# Tutorials |
Linux Tutorials |
PHP Tutorials |
ColdFusion Tutorials |
Windows Tutorials |
HTML/JavaScript Tutorials |
CSS Tutorials |
Flash Tutorials |
Web Promotion Tutorials |
Graphic Design & Photoshop Tutorials |
Software Development Tutorials |
Database Tutorials |
Other Language Tutorials |
ASP.NET Tutorials |
Game Programming Tutorials |
WPF & Silverlight Tutorials |
Mobile Development Tutorials |
Python Tutorials |
Ruby Tutorials |
