Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15129

Batch Print with Crystal Reports

$
0
0
Hey guys! :wave:

I was wondering if it's not too much trouble to ask for some help. I'm working with Crystal Reports and Visual Studio 2019 and writing in VB.Net. I'm really new to Crystal Reports so I'm kinda lost. What am I trying to accomplish? I'm writing a program that makes quotes to send to our dealers. I have one button that will create the report just fine. But what the women and men in the sales team like to do is create a "batch". So let's say the same dealer has five quotes in consecutive order. So they could be quote numbers 100-105. What they like to do click the "Print Batch" button and it would ask them a starting quote number and then the ending quote number. Then I would like it to print each quote on a separate page. If this was Access, I could just base my report off of a query and Access would generate the report for me. I was hoping to do something like that. I tried to Google this but didn't find the results I wanted. So I wrote some code, which might not be the best. I admit that.

Code:


      Dim cryRpt As New ReportDocument

        cryRpt.Load("MyFileLocation\rptCrystalReport1.rpt")

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        Try

            Dim intStart As Integer
            Dim intEnd As Integer
            Dim intCurrent As Integer

            'Get the starting and ending quotes from the user
            intStart = InputBox("Enter Start")
            intEnd = InputBox("Enter End")

            'Set the Starting quote number up to keep track of the loop
            intCurrent = intStart

            Do
                crParameterDiscreteValue.Value = intCurrent
                crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
                crParameterFieldDefinition = crParameterFieldDefinitions.Item("QuoteNum")
                crParameterValues = crParameterFieldDefinition.CurrentValues

                crParameterValues.Clear()
                crParameterValues.Add(crParameterDiscreteValue)
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

                'Make the Viewer Visible
                CrystalReportViewer1.Visible = True

                CrystalReportViewer1.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
                CrystalReportViewer1.ReportSource = cryRpt
                CrystalReportViewer1.Refresh()

                'Add one to the total
                intCurrent = intCurrent + 1

            Loop Until intCurrent = intEnd + 1

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

When I click my button, I can see the Report Viewer cycle thru each report. But the new report overrides the old one. I stepped thru the code and each time it gets to the line CrystalReportViewer1.ReportSource = cryRpt, the new report overrides the old one. Which I see why that happens. Is there a way to "append" the new quote on? Or is there a better method all together? I'd rather not someone just give me new code if I'm doing it wrong. I would like to learn and not just copy and paste. If you know what I mean.

I know using the InputBoxes isn't the best method. I want to replace those with text boxes.


Thanks for any help.
Y'all are the bestest!

Viewing all articles
Browse latest Browse all 15129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>