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