I am receiving an error from crystal reports that says i am missing parameters when i tell a report to print directly to a printer.
Here is the calling code.
Dim rdReport As CrystalDecisions.CrystalReports.Engine.ReportDocument
rdReport = PrintDocuments("Xbox Ticket")
'Main Report
rdReport.SetParameterValue("CustomerName", frm.cboCustomerName.Text.ToUpper)
rdReport.SetParameterValue("CustomerPhoneNumber", frm.lblPhoneNumber.Text.ToUpper)
'Details Subreport
rdReport.SetParameterValue("CashierName", Cashier, "Details")
rdReport.SetParameterValue("CustomerName", frm.cboCustomerName.Text.ToUpper, "Details")
rdReport.SetParameterValue("CustomerPhoneNumber", frm.lblPhoneNumber.Text.ToUpper, "Details")
rdReport.SetParameterValue("CopyField", "", "Details")
'Details2 Subreport
rdReport.SetParameterValue("CashierName", Cashier, "Details2")
rdReport.SetParameterValue("CustomerName", frm.cboCustomerName.Text.ToUpper, "Details2")
rdReport.SetParameterValue("CustomerPhoneNumber", frm.lblPhoneNumber.Text.ToUpper, "Details2")
rdReport.SetParameterValue("CopyField", "", "Details2")
rdReport.PrintOptions.PrinterName = My.Settings.ReportPrinter
rdReport.PrintToPrinter(1, True, 0, 0)
PrintDocuments is supposed to create a crystal report, prepopulate some parameter fields and then
return the report to the calling function to be displayed, printed, etc.
Here is the code for that.
Friend Function PrintDocuments(ByVal DocumentName As String) As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim rdReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rdReport.Load(frmMain.ProgramDefault.ReportPath & "\" & DocumentName & ".rpt")
'Set report Logon Info
Dim LogInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
With crConnectionInfo
.ServerName = DataServer.Server
.DatabaseName = DataServer.Database
If DataServer.Security Then
.IntegratedSecurity = DataServer.Security
Else
.IntegratedSecurity = DataServer.Security
.UserID = DataServer.UserName
.Password = DataServer.Password
End If
End With
LogInfo = New CrystalDecisions.Shared.TableLogOnInfo
LogInfo.ConnectionInfo = crConnectionInfo
Dim crTable As Table
For i As Integer = 0 To rdReport.Subreports.Count - 1
For Each crTable In rdReport.Subreports(i).Database.Tables
crTable.ApplyLogOnInfo(LogInfo)
Next crTable
Next
For Each crTable In rdReport.Database.Tables
crTable.ApplyLogOnInfo(LogInfo)
Next
'Look at parameter fields and fill in if found
Try
'Sub reports if found
For i As Integer = 0 To rdReport.Subreports.Count - 1
'if subreport does not have parameter fields don't worry about it
If rdReport.Subreports(i).ParameterFields Is Nothing Then Exit For
For l As Integer = 0 To rdReport.Subreports(i).ParameterFields.Count - 1
Select Case rdReport.Subreports(i).ParameterFields(l).Name
Case "CompanyName"
rdReport.Subreports(i).SetParameterValue("CompanyName", frmMain.ProgramDefault.CompanyName)
Case "CompanyStreet"
rdReport.Subreports(i).SetParameterValue("CompanyStreet", frmMain.ProgramDefault.CompanyStreet)
Case "CompanyCity"
rdReport.Subreports(i).SetParameterValue("CompanyCity", frmMain.ProgramDefault.CompanyCity)
Case "CompanyState"
rdReport.Subreports(i).SetParameterValue("CompanyState", frmMain.ProgramDefault.CompanyState)
Case "CompanyZip"
rdReport.Subreports(i).SetParameterValue("CompanyZip", frmMain.ProgramDefault.CompanyZip)
Case "CompanyPhone"
rdReport.Subreports(i).SetParameterValue("CompanyPhone", frmMain.ProgramDefault.CompanyPhone)
Case "CompanyFax"
rdReport.Subreports(i).SetParameterValue("CompanyFax", frmMain.ProgramDefault.CompanyFax)
Case "CompanyWeb"
rdReport.Subreports(i).SetParameterValue("CompanyWeb", frmMain.ProgramDefault.CompanyWeb)
Case "CashierName"
rdReport.Subreports(i).SetParameterValue("CashierName", Cashier)
End Select
Next
Next
Catch ex As Exception
End Try
'Main reports
For i As Integer = 0 To rdReport.ParameterFields.Count - 1
Select Case rdReport.ParameterFields(i).Name
Case "CompanyName"
rdReport.SetParameterValue("CompanyName", frmMain.ProgramDefault.CompanyName)
Case "CompanyStreet"
rdReport.SetParameterValue("CompanyStreet", frmMain.ProgramDefault.CompanyStreet)
Case "CompanyCity"
rdReport.SetParameterValue("CompanyCity", frmMain.ProgramDefault.CompanyCity)
Case "CompanyState"
rdReport.SetParameterValue("CompanyState", frmMain.ProgramDefault.CompanyState)
Case "CompanyZip"
rdReport.SetParameterValue("CompanyZip", frmMain.ProgramDefault.CompanyZip)
Case "CompanyPhone"
rdReport.SetParameterValue("CompanyPhone", frmMain.ProgramDefault.CompanyPhone)
Case "CompanyFax"
rdReport.SetParameterValue("CompanyFax", frmMain.ProgramDefault.CompanyFax)
Case "CompanyWeb"
rdReport.SetParameterValue("CompanyWeb", frmMain.ProgramDefault.CompanyWeb)
Case "CashierName"
rdReport.SetParameterValue("CashierName", Cashier)
End Select
Next
LogInfo = Nothing
crTable = Nothing
crConnectionInfo = Nothing
Return rdReport
End Function
i'm not sure but it seems that the parameters being set by the calling code are not being set properly.
Here is the original code, i modified it to be reusable in multiple different places but now i am running into this problem
Private Function PrintGameReceipt() As PrintingErrors
If Not frmMain.ProgramDefault.AllowPrinter Then Return PrintingErrors.OK
frmMain.Cursor = Cursors.WaitCursor
Try
Dim rdReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
'rdReport = PrintDocuments("Xbox Ticket")
'Dim rpath As String = RepPath
rdReport.Load(frmMain.ProgramDefault.ReportPath & "\" & "Xbox Ticket.rpt")
Dim LogInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
With crConnectionInfo
.ServerName = DataServer.Server
.DatabaseName = DataServer.Database
If DataServer.Security Then
.IntegratedSecurity = DataServer.Security
Else
.IntegratedSecurity = DataServer.Security
.UserID = DataServer.UserName
.Password = DataServer.Password
End If
End With
LogInfo = New CrystalDecisions.Shared.TableLogOnInfo
LogInfo.ConnectionInfo = crConnectionInfo
Dim crTable As Table
For i As Integer = 0 To rdReport.Subreports.Count - 1
For Each crTable In rdReport.Subreports(i).Database.Tables
crTable.ApplyLogOnInfo(LogInfo)
Next crTable
Next
For Each crTable In rdReport.Database.Tables
crTable.ApplyLogOnInfo(LogInfo)
Next
rdReport.SetParameterValue("CompanyName", frmMain.ProgramDefault.CompanyName)
rdReport.SetParameterValue("CompanyStreet", frmMain.ProgramDefault.CompanyStreet)
rdReport.SetParameterValue("CompanyCity", frmMain.ProgramDefault.CompanyCity)
rdReport.SetParameterValue("CompanyState", frmMain.ProgramDefault.CompanyState)
rdReport.SetParameterValue("CompanyZip", frmMain.ProgramDefault.CompanyZip)
rdReport.SetParameterValue("CompanyPhone", frmMain.ProgramDefault.CompanyPhone)
rdReport.SetParameterValue("CompanyFax", frmMain.ProgramDefault.CompanyFax)
rdReport.SetParameterValue("CompanyWeb", frmMain.ProgramDefault.CompanyWeb)
rdReport.SetParameterValue("CashierName", Cashier)
rdReport.SetParameterValue("CustomerName", frm.cboCustomerName.Text.ToUpper)
rdReport.SetParameterValue("CustomerPhoneNumber", frm.lblPhoneNumber.Text.ToUpper)
'Details Section
rdReport.SetParameterValue("CompanyName", frmMain.ProgramDefault.CompanyName, "Details")
rdReport.SetParameterValue("CompanyStreet", frmMain.ProgramDefault.CompanyStreet, "Details")
rdReport.SetParameterValue("CompanyCity", frmMain.ProgramDefault.CompanyCity, "Details")
rdReport.SetParameterValue("CompanyState", frmMain.ProgramDefault.CompanyState, "Details")
rdReport.SetParameterValue("CompanyZip", frmMain.ProgramDefault.CompanyZip, "Details")
rdReport.SetParameterValue("CompanyPhone", frmMain.ProgramDefault.CompanyPhone, "Details")
rdReport.SetParameterValue("CompanyFax", frmMain.ProgramDefault.CompanyFax, "Details")
rdReport.SetParameterValue("CompanyWeb", frmMain.ProgramDefault.CompanyWeb, "Details")
rdReport.SetParameterValue("CashierName", Cashier, "Details")
rdReport.SetParameterValue("CustomerName", frm.cboCustomerName.Text.ToUpper, "Details")
rdReport.SetParameterValue("CustomerPhoneNumber", frm.lblPhoneNumber.Text.ToUpper, "Details")
rdReport.SetParameterValue("CopyField", "", "Details")
'Details2 Section
rdReport.SetParameterValue("CompanyName", frmMain.ProgramDefault.CompanyName, "Details2")
rdReport.SetParameterValue("CompanyStreet", frmMain.ProgramDefault.CompanyStreet, "Details2")
rdReport.SetParameterValue("CompanyCity", frmMain.ProgramDefault.CompanyCity, "Details2")
rdReport.SetParameterValue("CompanyState", frmMain.ProgramDefault.CompanyState, "Details2")
rdReport.SetParameterValue("CompanyZip", frmMain.ProgramDefault.CompanyZip, "Details2")
rdReport.SetParameterValue("CompanyPhone", frmMain.ProgramDefault.CompanyPhone, "Details2")
rdReport.SetParameterValue("CompanyFax", frmMain.ProgramDefault.CompanyFax, "Details2")
rdReport.SetParameterValue("CompanyWeb", frmMain.ProgramDefault.CompanyWeb, "Details2")
rdReport.SetParameterValue("CashierName", Cashier, "Details2")
rdReport.SetParameterValue("CustomerName", frm.cboCustomerName.Text.ToUpper, "Details2")
rdReport.SetParameterValue("CustomerPhoneNumber", frm.lblPhoneNumber.Text.ToUpper, "Details2")
rdReport.SetParameterValue("CopyField", "", "Details2")
rdReport.PrintOptions.PrinterName = My.Settings.ReportPrinter
rdReport.PrintToPrinter(1, True, 0, 0)
Catch ex As Exception
frmMain.Cursor = Cursors.Default
Dim vd As New VDialog()
With vd
.Buttons = New VDialogButton() {New VDialogButton(VDialogResult.OK)}
.WindowTitle = "Print Error"
.MainInstruction = "Print Error"
.MainIcon = VDialogIcon.Error
.Content = "Error Printing Receipts"
.FooterIcon = VDialogIcon.Error
.FooterText = "Print Error"
.ExpandedControlText = "Hide Info "
.CollapsedControlText = "Show Info "
.ExpandedInformation = "Extra Information" & vbCrLf & ControlChars.CrLf & ex.Message
.ExpandFooterArea = True
.ExpandedByDefault = False
.Show()
End With
WriteToEventLog("Error Printing Receipts (Game Form Class): " & vbCrLf & ex.Message, , EventLogEntryType.Error, , 227)
Return PrintingErrors.BadData
End Try
frmMain.Cursor = Cursors.Default
Return PrintingErrors.OK
End Function
Any help would be greatly appreciated.
modified on Friday, July 24, 2009 9:43 AM
|