V
Vax
Guest
I have this code, and it's supposed to print a Crystal Report. It runs, gives control back to the user, and never prints out the report. Anyone see something wrong with the code?
Visual Basic:
Try
rResp = MsgBox("Do you want to print a report of unmatched data? This will show previous records that are no longer on the Gains roster.", MsgBoxStyle.Question Or MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton1, "Print Unmatched Report?")
If rResp = MsgBoxResult.No Then Exit Sub
dbAdapter.SelectCommand.CommandText = "SELECT [Gains].[SSN], [Gains].[Rank], [Gains].[Name], [Gains].[MOS], [Gains].[Requisition], [Gains].[ArrivalDate], [Gains].[DepartureDate], [Gains].[LosingUIC], [Gains].[Code1], [Gains].[ETS], [Gains].[Code2], [Gains].[GainingUIC], [Gains].[GainingUnit], [Gains].[GainingLocation], [Gains].[GainingState], [Gains].[GainingZip], [Gains].[Code3], [Gains].[MACOM], [Gains].[Code4], [Gains].[OrdersDate], [Gains].[DutyMOS], [Gains].[UnitAssignment], [Gains].[Comments] FROM Gains WHERE (((Gains.SSN) In (SELECT [SSN] FROM [Gains] As Tmp GROUP BY [SSN] HAVING Count(*)=1 ))) ORDER BY [Gains].[SSN]"
dbAdapter.Fill(dtTable)
crRpt.SetDataSource(dtTable)
CrystalReportViewer.ReportSource = crRpt
With dialogPrint
.AllowPrintToFile = True
.AllowSomePages = True
.AllowSelection = True
.PrintToFile = False
.ShowNetwork = True
.Document = New Printing.PrintDocument()
.ShowDialog()
crRpt.PrintOptions.PrinterName = .PrinterSettings.PrinterName
crRpt.PrintToPrinter(1, True, .PrinterSettings.FromPage, .PrinterSettings.ToPage)
End With
crRpt.Close()
Catch err As Exception
MsgBox(String.Concat("There was an error with the print command.", ControlChars.CrLf, err.Message, ControlChars.CrLf, "In ", err.Source), MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly, "Printing Error")
End Try
Last edited by a moderator: