Hello all,
I have been reading and searching for an answer to this and I'm unable to locate anything. I have written a program in which a farmer creates a ticket and prints a bill of lading. On the print button I execute the following code:
Try
successSaveTicket = saveTicketDetails()
If successSaveTicket = True Then
If Me.lstDetails.Items.Count > 0 Then
Dim newticket As New rptTicket
Dim reportViewer As New frmReportViewer
'================================
newticket.Load()
'
' Declare the parameter related objects.
'
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldLocation As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
'
' Get the report's parameters collection.
'
crParameterFieldDefinitions = newticket.DataDefinition.ParameterFields
'
' Set the first parameter
' - Get the parameter, tell it to use the current values vs default value.
' - Tell it the parameter contains 1 discrete value vs multiple values.
' - Set the parameter's value.
' - Add it and apply it.
' - Repeat these statements for each parameter.
'
crParameterFieldLocation = crParameterFieldDefinitions.Item("ticketNumber")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = Long.Parse(Me.txtTicketNumber.Text)
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
newticket.PrintToPrinter(1, False, 0, 0)
fillOpenTickets()
clearLoadDetails()
Me.grpLoadDetails.Enabled = True
Me.grpCreateTicket.Enabled = False
Me.grpTickets.Enabled = True
ErrorProvider1.Clear()
Me.btnNewTicket.Focus()
'Show report in viewer to print? is causing memory error though
reportViewer.viewer.ReportSource = newticket
reportViewer.Show()
Else
MsgBox("There are no related details for this ticket to print")
Me.cmbProduct.Focus()
End If
End If
Catch ex As Exception
MsgBox("Error in printing: " & ex.Message.ToString)
End Try
Edited by: Don Williams on Feb 27, 2011 7:06 AM