Question

I am currently having a problem whilst passing date parameters from vb.net to Crystal Report XI

I have written a number of reports and have never had a problem whilst passing a parameter, but having said that this is the first time that I have passed a date

It appears to completely ignore the parameters that I am passing and continually asks me to enter a start date(SDate) and end date(EDate)

here is my code

Public Sub GenerateInvoiceByDate(ByVal SDate As Date, ByVal EDate As Date, ByVal boolByAccount As Boolean, ByVal strAccountRef As String)
    Dim strSelectionText As String = ""
    Dim theReport As New ReportDocument
    theReport.FileName = strReportLocation & "Invoice2.rpt"

    theReport.SetParameterValue("SDate", Format(SDate, "dd/MM/yyyy"))
    theReport.SetParameterValue("EDate", Format(EDate, "dd/MM/yyyy"))
    theReport.SetParameterValue("AccountRef", strAccountRef)

    If boolByAccount = True Then
        'generate an invoice for a specific customer account between two dates
        strSelectionText = "{InvoiceHeader.CustomerRef}= {?AccountRef} and {InvoiceHeader.CreatedOn} in {?SDate} to {?EDate}"
    Else
        'generate all invoices between two dates
        strSelectionText = "{InvoiceHeader.CreatedOn} in {?SDate} to {?EDate}"
    End If

    theReport.RecordSelectionFormula = strSelectionText

    theReport.SetDatabaseLogon(strDatabaseUser, strDatabasePassword)

    ReportView.CRView.ReportSource = theReport

    ReportView.ShowDialog()

End Sub

I was assuming that the problem was with the format of the date that Crystal reports was expecting, hence i introduced that Format() method. I have confirmed that crystal is expecting a date and not date time. The two dates are passed to the method via the following code

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    CropTrackMod.GenerateInvoiceByDate(dtpSDate.Value, dtpEDate.Value, chkByAccount.Checked, txtAccountRef.Text)

End Sub

I am starting to run out of ideas and would appreciate anyone who can shed light on my problem.

Thanks in advance guys

UPDATE: I have now changed my code as follows. If i set a start date and end date then it works OK. When i attempt to set an account ref when boolaccount = true i get the prompt for "AccountRef". I just cant understand why it keeps loosing that one value.

here is my updated code

'Test Sub for adding parameter fields to crystal reports dynamicly
Public Sub TESTGenerateInvoiceByDate(ByVal SDate As DateTime, ByVal EDate As DateTime, ByVal boolByAccount As Boolean, ByVal strAccountRef As String)
    Dim strSelectionText As String = ""
    Dim theReport As New ReportDocument
    theReport.FileName = strReportLocation & "Invoice2.rpt"
    'theReport.Load(strReportLocation & "Invoice2.rpt")

    ReportView.CRView.ReuseParameterValuesOnRefresh = True

    If boolByAccount = True Then
        theReport.SetParameterValue("SDate", SDate)
        theReport.SetParameterValue("EDate", EDate)
        theReport.SetParameterValue("AccountRef", strAccountRef.ToUpper.ToString)
        'theReport.SetParameterValue("Changed", "True")
        'theReport.SetParameterValue("InvoiceRef", "")
        'theReport.SetParameterValue("New", "True")

        'generate an invoice for a specific customer account between two dates
        strSelectionText = "{InvoiceHeader.CustomerRef} = {?AccountRef} and {InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
    Else
        theReport.SetParameterValue("SDate", SDate)
        theReport.SetParameterValue("EDate", EDate)
        theReport.SetParameterValue("AccountRef", "")
        'theReport.SetParameterValue("AccountRef", strAccountRef)
        'theReport.SetParameterValue("Changed", "True")
        'theReport.SetParameterValue("InvoiceRef", "")
        'theReport.SetParameterValue("New", "True")

        'generate all invoices between two dates
        strSelectionText = "{InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
    End If

    theReport.RecordSelectionFormula = strSelectionText
    ReportView.CRView.ReportSource = theReport



    theReport.SetDatabaseLogon(strDatabaseUser, strDatabasePassword)

    'ReportView.CRView.Refresh()

    ReportView.ShowDialog()

End Sub

If i insert a breakpoint at the end of the sub on the showdialog i can see that the "HasRecords" property of the report document has a value of "HasRecords = {"Missing parameter values."}"

I have confirmed in the report designer that there are only 3 parameter fields

I can confirm that if i enter a value manually when the report viewer prompts the report does work.

Was it helpful?

Solution

I am glad to say that i have now resolved the problem i was having above

it was due to the order in which i was setting properties of the Report Document

I needed to supply the record select formula prior to setting the parameter values

my working code is as follows

Public Sub GenerateInvoiceByDate(ByVal SDate As DateTime, ByVal EDate As DateTime, ByVal boolByAccount As Boolean, ByVal strAccountRef As String)
    Dim strSelectionText As String = ""
    Dim theReport As New ReportDocument
    theReport.FileName = strReportLocation & "Invoice2.rpt"
    'theReport.Load(strReportLocation & "Invoice2.rpt")

    ReportView.CRView.ReuseParameterValuesOnRefresh = True

    If boolByAccount = True Then
        'generate an invoice for a specific customer account between two dates
        strSelectionText = "{InvoiceHeader.CustomerRef} = {?AccountRef} and {InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
        theReport.RecordSelectionFormula = strSelectionText

        theReport.SetParameterValue("SDate", SDate)
        theReport.SetParameterValue("EDate", EDate)
        theReport.SetParameterValue("AccountRef", strAccountRef.ToUpper.ToString)
        theReport.SetParameterValue("Changed", "True")
        theReport.SetParameterValue("InvoiceRef", "")
        theReport.SetParameterValue("New", "True")

    Else
        'generate all invoices between two dates
        strSelectionText = "{InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
        theReport.RecordSelectionFormula = strSelectionText

        theReport.SetParameterValue("SDate", SDate)
        theReport.SetParameterValue("EDate", EDate)
        theReport.SetParameterValue("AccountRef", "")
        theReport.SetParameterValue("AccountRef", strAccountRef)
        theReport.SetParameterValue("Changed", "True")
        theReport.SetParameterValue("InvoiceRef", "")
        theReport.SetParameterValue("New", "True")



    End If

    ReportView.CRView.ReportSource = theReport



    theReport.SetDatabaseLogon(strDatabaseUser, strDatabasePassword)

    'ReportView.CRView.Refresh()

    ReportView.ShowDialog()

End Sub

Good luck and tanks to all that helped

OTHER TIPS

You probably are passing string values to a date parameter. change this line : theReport.SetParameterValue("SDate", Format(SDate, "dd/MM/yyyy")) with: theReport.SetParameterValue("SDate", SDate)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top