Solved

Referencing a variable in Crystal reports that is set in a windows form using VB.net

Posted on 2006-11-12
3
212 Views
Last Modified: 2012-06-27
I have a form that fires a crystal report...this works all fine ... the problem is I have the actual firing of the report within a loop, the actual report only returns 1 invoice number but based on the number of times the loop has to execute, the same report could be fired several times. I want to record the number of the loop in the actual report. For example , the first time through the loop I want to see the #1 on the report, the second time through I want to see the number #2 on the report, etc...

How would I pass that number into the report and what would I have to set up on the actual report to handle the value being passed??

This is the code I have so far. The variable "lnBagCount" determines the length of  the loop.Basically each time through the loop I want to see value of "D" to appear in the report...

        Dim cr2 As New CrystalReport3
        Dim strFilter As String
        Dim D As Integer
        strFilter = "{tInv.IID}= " & InvoiceID & ""
        CrystalReportViewer1.SelectionFormula = strFilter
        CrystalReportViewer1.ReportSource = cr2
        cr2.RecordSelectionFormula = "{tInv.IID}= " & InvoiceID & ""

        For D = 1 To lnBagCount
            cr2.Refresh()
            cr2.PrintToPrinter(1, False, 0, 0)
        Next

Now in the actual Crystal Report itself, I have following formula code that  shows the InvoiceNumber

StringVar InvoiceNumber;

InvoiceNumber := Replace(CStr({tInv.iInvNum}),".00" ,"" );

"*" & InvoiceNumber & "-" & D  & "*"

' if you notice the line above I want "d" to be appended to the invoice number, this is supposed the number of times the report has been printed

Any insight or help would be much apreciated...
0
Comment
Question by:nomar2
3 Comments
 
LVL 7

Accepted Solution

by:
ast2550 earned 55 total points
ID: 17930213
You need a parameter field in the report

Then you pass the value into the report through the parameter

http://www.codeproject.com/vb/net/CrystalContrl.asp
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 17930814
You could also add a formula to the report and change it from the VB code.

Here are some VB.Net samples.  

http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_win_samples.exe.asp

mlmcc
0
 

Author Comment

by:nomar2
ID: 17937676
Thanks Ast2550... I added a parameter to the report called Parameter1

 and then on the vb side of the code I added the following

     For D = 1 To lnBagCount
            ' added this line to my code block
            cr2.SetParameterValue("Parameter1", D) ' populates the parameter in the Crystal rpt
            cr2.PrintToPrinter(1, False, 0, 0)
        Next
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question