Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call a .RPT report from a form

Status
Not open for further replies.

chocolat

Programmer
Dec 17, 2002
1
BE
Hi!

I am really new in programming with VB. I would like to run a Crystal reports from a VB form after the user has selected the report he wants to run. I do not know why, but I cannot find which command I have to run. I tried the SHELL command but it looks like it is only working with an .EXE file.

Anyone could help me?
Here is the code I made.

Public strMessage As String
Private Sub File1_Click()
drivelist.Drive = "c:"
End Sub

Private Sub cmdCancel_Click()
MsgBox "CANCELLED"
Unload Me
End Sub

Private Sub cmdOK_Click()
Dim strMessage
   strMessage = "Drive: " & drvDialog.Drive
   strMessage = strMessage & vbCr & "Path: " & dirDialog.Path
    strMessage = strMessage & vbCr & "Filename: " & filDialog.FileName
    strMessage = strMessage & vbCr & "The lot: "
    If Right(filDialog.Path, 1) = "\" Then
    strMessage = filDialog.Path & filDialog.FileName
   Else
   strMessage = filDialog.Path & "\" & filDialog.FileName
   End If
  MsgBox strMessage

  'ret = Shell(strMessage, 1)
'Instead of running this report.exe, I would like to run a .RPT file
  Unload Me
  End Sub

Private Sub Form_Load1()
Dim crApplication As New CRAXDRT.Application
Dim Report As CRAXDRT.Report
Set Report = crApplication.OpenReport("C:\activity.rpt")

'Set Report = crApplication.OpenReport("strMessage")
With Report.Database.Tables(1).ConnectionProperties
.Item("DSN") = "I"
.Item("Database") = "I"
.Item("User ID") = "laurence"
.Item("Password") = "laurence"
End With

'Private Sub form_load()
Screen.MousePointer = vbHourglass
CRViewer91.ReportSource = Report
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize1()
CRViewer91.Top = 0
CRViewer91.Left = 0
CRViewer91.Height = ScaleHeight
CRViewer91.Width = ScaleWidth
End Sub

Private Sub dirDialog_Change()
filDialog.Path = dirDialog.Path
End Sub

Private Sub drvDialog_Change()
drivelist.Drive "c:" Or "e:"
dirDialog.Path = drvDialog.Drive
End Sub

Private Sub filDialog_Click()
txtFilename.Text = filDialog.FileName
End Sub

Private Sub filDialog_Change()
Me.Caption = "Dialog Box - [" & filDialog.Path & "]"
End Sub
 
If i were you i would probably start by going through VB samples which crystal reports comes with.The typical location of those sampes will be:

C:\Program Files\Seagate Software\Crystal Reports\Samples\En\Code\Visual Basic
 
Look up the examples about using the RDC.

The minimum code you will need is....
Public Appn As CRAXDRT.Application
Public cReport As CRAXDRT.Report

Set Appn = New CRAXDRT.Application
Set cReport = Appn.OpenReport(filDialog.Path & "\" & _
filDialog.FileName)
cReport.PrintReport //to print to the default printer

A couple more lines of code and viewer form are needed if you want a preview. There are over 300 properties and methods you can play with. Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top