Cancel Report With SubReport

skea

Registered User.
Local time
Tomorrow, 00:39
Joined
Dec 21, 2004
Messages
342
I have a Report linked with a SubReport. I would like to cancel viewing this Report if my SubReport Has No Data.
i tried this code but the report just shows up. Any Ideas?
Code:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Trapper
If Reports![qryRepCurOrgProjsSR].Report.HasData = 0 Then
Cancel = True
End If
Err_Trapper:
MsgBox Err.Description
Exit Sub
End Sub

Ok i got an error message. Yoy entered an expression that has an invalid Reference to the hasData property.

Ive tried using a text bpx on my main report and putting a control source as
Code:
=IIf(qryRepCurOrgProjsSR.Report.HasData,0,"Nothing")
Then in my Report Open Event i put the code below. But it fails me still.
Code:
If trim(Me.MyText) = "Nothing" Then
MsgBox "The Report Is Cancelling....."
Cancel = True
Exit Sub
End If
 
Last edited:
You could 'bodge' you way round it by testing manually to see if the query behind the report has records before opening the report. If there are no records in the SQL dont bother.

Dim dbs as Database
Dim rst as recordset
Dim strSQL as string

set dbs = currentdb

strSQL = "Query from sub report"
Set rst = dbs.openrecordset(strsql, dbopensnapshot)
if rst.eof then
'no records exist
else
Docmd.openreport blarblar
end if
rst.close


Just a thought.

Stu
 
good.

i was wondering if there is way to use hasData.
 

Users who are viewing this thread

Back
Top Bottom