|
-
Nov 22nd, 2000, 02:50 PM
#1
Thread Starter
Hyperactive Member
This is a dumb question, but I would appreciate
if someone can explain.
I know Crystal Reports is a reporting tools, but
how does it work with VB, and where can I find code sample (simple one)?
-
Nov 22nd, 2000, 08:43 PM
#2
Its kind of its own deal because the reports are stored as rpt files and I think it makes a seperate connection to the database, but it can be called from VB. I have only used the eval version and the old Report component that had more free design tools. The actual report making is alot like Access. You can even run a wizard from Access or Excel to make reports and then call them from VB. but basically when you can the datareport object through the CRViewer that takes care of the coding. just disect the sample if you have downloaded it.
-
Nov 23rd, 2000, 05:13 AM
#3
Fanatic Member
Cristal does make its own connection to the database. The way I do this is to create a form template with the CRViewer control on it.
Ensure the references are set in the Project menu for any project that uses this form:
Cristal Report Viewer Control
Cristal Report 8 ActiveX Designer Run Time Library
(the 8 is version 8 that we use, you may have a different version)
Create a new form and place the CRViewer control on it and paste the following code on the form:
Code:
Option Explicit
Dim Appl As CRAXDRT.Application
Dim Report As New CRAXDRT.Report
' holds the report file path
Private mRepFile As String
Private Sub Form_Load()
Set Appl = New CRAXDRT.Application
Set Report = Appl.OpenReport(mRepFile)
Report.DiscardSavedData
Report.Database.Tables(1).SetLogOnInfo <database>, , <UserID>, <password>
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
CRViewer1.Top = 0
CRViewer1.Left = 0
End Sub
Private Sub Form_Resize()
' keeps the CRViewer the same size as the form
CRViewer1.Width = Me.ScaleWidth
CRViewer1.Height = Me.ScaleHeight
End Sub
' Property to allow the report path to be passed in
Property Let ReportFile(rep As String)
mRepFile = rep
End Property
Private Sub Form_Unload(Cancel As Integer)
Set Appl = Nothing
Set Report = Nothing
End Sub
Now you have a reusable form, for any developer to use and for any program.
You can add more porperties to allow the passing in of the security info (userid,password)
Then when you want to display a report include the form (and references) in your project then place the following code on the calling form:
Code:
Private Sub mnuOutstanding_Click()
frmReportView.ReportFile = App.Path & "\Students.rpt"
frmReportView.Caption = "Crystal Report Viewer [Students.rpt]"
frmReportView.Show vbModal
frmReportView.ReportFile = ""
Set frmReportView = Nothing
End Sub
if you have more questions email me or post another question. I will try to help if possible.
good luck
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|