I actually figured this out a while go. I'm pretty sure I posted the solution here too, but cannot find it, so this should help you.
Basically, I create a form with a Crystal Report Viewer object on it. Then put a button on another form and put some code like the following in it:
Code:Private Sub btnPrintDaily_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintDaily.Click Dim conDB As New OleDb.OleDbConnection() conDB = ConnectToDatabase() Dim fdate, sdate As DateTime Dim tbl As CrystalDecisions.CrystalReports.Engine.Table Dim rpt As New rpt0003() rpt.DataDefinition.RecordSelectionFormula = "{tbl_TableName.FieldName} = " & ParameterValue For Each tbl In rpt.Database.Tables Dim tbllogin As New CrystalDecisions.Shared.TableLogOnInfo() tbllogin.ConnectionInfo.ServerName = gstrDatabasePath tbllogin.ConnectionInfo.UserID = "admin" tbllogin.ConnectionInfo.Password = gcDatabasePassword tbl.ApplyLogOnInfo(tbllogin) Next Dim frmRpt As New frmReportViewer() With frmRpt .CrystalReportViewer1.ReportSource = rpt .CrystalReportViewer1.RefreshReport() .CrystalReportViewer1.DisplayGroupTree = False .Left = Me.Left .Top = Me.Top .Icon = Me.Icon .Text = "Title Text Here" .ShowDialog() End With conDB.Close() conDB.Dispose() End Sub




Reply With Quote