[RESOLVED] Load a Report Programmatically
I got this code from a book but there are errors all over this:
VB Code:
Me.Cursor = Cursors.WaitCursor
Try
Dim oRpt As New ReportDocument
oRpt.Load("..\Reports\" & strTransaction)
Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tbCurrent In oRpt.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = "localhost"
.UserID = "sa"
.Password = "corbin"
.DatabaseName = "BiWeekly"
End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent
viewer.ReportSource = oRpt
Catch ex As Exception
MsgBox(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try
The errors are saying:
Cannot find custom tool 'CrystalDecisions.VSDesigner.CodeGen.ReportCodeGenerator' on this system.
Name 'viewer' is not declared
Name 'strTransaction' is not declared.
Type 'CrystalDecisions.CrystalReports.Engine.Table' is not defined
Type 'CrystalDecisions.Shared.TableLogOnInfo' is not defined
Type 'ReportDocument' is not defined
I need some advice how to resolve these issues.
Thanks.
Re: Load a Report Programmatically
have you referenced your crystal report on your project?
Re: Load a Report Programmatically
Looks like your using vb.net with Option Explicit on. So you need to declare the strTransaction for starters. the rest of the problems will be fixed if you add the reference to Crystal and place the CR Viewer control on your form.
VB Code:
Me.Cursor = Cursors.WaitCursor
Try
Dim strTransaction As String
Dim oRpt As New ReportDocument
oRpt.Load("..\Reports\" & strTransaction)
Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tbCurrent In oRpt.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = "localhost"
.UserID = "sa"
.Password = "corbin"
.DatabaseName = "BiWeekly"
End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent
viewer.ReportSource = oRpt
Catch ex As Exception
MsgBox(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try