cancel report if subreport has no data

G

Guest

I can not use the no data event on my main report to cancel opening as it
always has some data. If my subreport has no data though I would like the
main report to cancel opening.

Tried the following but I get error 2455, Invalid reference to the property
form/report

If Me![Expenses Weekly].Report.HasData = False Then
Cancel = True
Msg = "No Expenses for " & Forms![frm resource menu]![txtSpecialist] & _
" w/e " & Forms![frm resource menu]![StartDate] + 4
MsgBox Msg, vbInformation
End If

Can anyone help with this please?

Thanks
Sue
 
G

Guest

Use the code on the OnActivate event of the main report

If Me![Expenses Weekly].Report.HasData = False Then
Msg = "No Expenses for " & Forms![frm resource menu]![txtSpecialist] & _
" w/e " & Forms![frm resource menu]![StartDate] + 4
MsgBox Msg, vbInformation
DoCmd.Close acReport, "Report Name"
End If
 
G

Guest

Thanks that sorted it!

Sue


Ofer said:
Use the code on the OnActivate event of the main report

If Me![Expenses Weekly].Report.HasData = False Then
Msg = "No Expenses for " & Forms![frm resource menu]![txtSpecialist] & _
" w/e " & Forms![frm resource menu]![StartDate] + 4
MsgBox Msg, vbInformation
DoCmd.Close acReport, "Report Name"
End If

--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



hughess7 said:
I can not use the no data event on my main report to cancel opening as it
always has some data. If my subreport has no data though I would like the
main report to cancel opening.

Tried the following but I get error 2455, Invalid reference to the property
form/report

If Me![Expenses Weekly].Report.HasData = False Then
Cancel = True
Msg = "No Expenses for " & Forms![frm resource menu]![txtSpecialist] & _
" w/e " & Forms![frm resource menu]![StartDate] + 4
MsgBox Msg, vbInformation
End If

Can anyone help with this please?

Thanks
Sue
 
G

Guest

Hi Ofer,

I tried the advice you gave in this post, but my report still opens!

I have checked spelling, that "[Event Procedure]" is in the properties
window for Activate, and everything else I could think of. The report opens.
Is there anything else I can try?

here is the code:

Private Sub Report_Activate()
If Me![rpsStyleCommHist].Report.HasData = False Then
Msg = "There are no comments for style " & Me!Style_pk & ". Please choose
another style."
MsgBox Msg, vbInformation
DoCmd.Close acReport, "rptStyleCommHist"
End If
End Sub

I also tried without the square brackets.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top