|
-
Jan 25th, 2008, 10:58 AM
#1
Thread Starter
Hyperactive Member
[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!
Last edited by kevchadders; Jan 31st, 2008 at 03:40 AM.
-
Jan 25th, 2008, 11:18 AM
#2
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 28th, 2008, 11:24 AM
#3
Thread Starter
Hyperactive Member
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.
-
Jan 28th, 2008, 01:32 PM
#4
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
-
Jan 28th, 2008, 02:25 PM
#5
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 28th, 2008, 03:32 PM
#6
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.
-
Jan 29th, 2008, 05:24 AM
#7
Thread Starter
Hyperactive Member
Re: Stopping a Crystal Report using VB6 when there is no data
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|