[RESOLVED] Stopping a Crystal Report using VB6 when there is no data
Hi,
I am building a SQL formula dynamically to pass to Crystal Reports RecordSelectionFormula property so that i can generate a report with different criteria.
This means that occasionally the search criteria will return nothing. So instead of getting back a blank report with just the column headings showing, is there a quick way to check to see if there is any data being passed back to the crystal report so that i can intercept this in code and hide the report from being shown to the user.
I am aware of a event called NoData, which seems perfect for this but i cannot seem to be able to access it in VB6. (Grrrr)
Its Friday, so maybe i'm missing something obvious here!
Any help would be appreciated on how to do this or a piece of code on how to trap the NoData event in VB6 as i cant seem to do it!
Re: Stopping a Crystal Report using VB6 when there is no data
Not that I know of but if you wanted to query completely in your recordset to include whatever selection formula stuff you are doing in CR so its all in the sql query then you could query it, check for records, and if so pass it to the CR reports data source.
Re: Stopping a Crystal Report using VB6 when there is no data
yeah, that way is an option but its means extra code to pass the SQL over to see if any records exist.
Just though there might be a quick way to check if Crystal Reports has returned any data back.
Thanks.
Re: Stopping a Crystal Report using VB6 when there is no data
Which version of Crystal are you using?
In 8.5, using the ReadRecords and GetNextRows methods work on a simple report.
Code:
Dim objApp As New CRAXDRT.Application
Dim objRep As CRAXDRT.Report
Dim varRec As Variant
Dim blnNoData As Boolean
Set objRep = objApp.OpenReport("C:\report1.rpt")
objRep.RecordSelectionFormula = "{Customers.CustomerID} = 'WOLZA'"
objRep.ReadRecords
varRec = objRep.GetNextRows(0, 1)
If IsArray(varRec) Then
blnNoData = IsEmpty(varRec(0, 0))
Else
blnNoData = True
End If
If Not blnNoData Then
CRViewer1.Visible = True
CRViewer1.ReportSource = objRep
CRViewer1.ViewReport
End If
Set objRep = Nothing
Set objApp = Nothing
Re: Stopping a Crystal Report using VB6 when there is no data
The NoDate is an event that you can hook with the CRAXDRT.Report object.
Re: Stopping a Crystal Report using VB6 when there is no data
The NoData event fires when you call the CRViewer.ViewReport method. It does not fire when the ReadRecords method is used. If I understand the OP correctly that is to late although there is probably a work around in that situation as well.
Re: Stopping a Crystal Report using VB6 when there is no data
Quote:
Originally Posted by brucevde
Which version of Crystal are you using?
In 8.5, using the ReadRecords and GetNextRows methods work on a simple report.
Code:
Dim objApp As New CRAXDRT.Application
Dim objRep As CRAXDRT.Report
Dim varRec As Variant
Dim blnNoData As Boolean
Set objRep = objApp.OpenReport("C:\report1.rpt")
objRep.RecordSelectionFormula = "{Customers.CustomerID} = 'WOLZA'"
objRep.ReadRecords
varRec = objRep.GetNextRows(0, 1)
If IsArray(varRec) Then
blnNoData = IsEmpty(varRec(0, 0))
Else
blnNoData = True
End If
If Not blnNoData Then
CRViewer1.Visible = True
CRViewer1.ReportSource = objRep
CRViewer1.ViewReport
End If
Set objRep = Nothing
Set objApp = Nothing
I'm using a mix of 8.5 and XI Release 2 (v11r2)
I have used part of your example, and changed part of your code to get it done thanks.
(code i used below)
Code:
' Read the record
crptAny.ReadRecords
' Store what in the data
varRec = crptAny.GetNextRows(0, 1)
' Check to see if we can show the report
If IsEmpty(varRec(0, 0)) Then
lblnOKToReport = False
Else
lblnOKToReport = True
End If
ps. Thank Bruce, and the rest for you contribution :)