Close report that has no data

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I have
Private Sub Report_NoData(Cancel As Integer)
msgbox ""
docmd.close acform,name

but the close command generates an error. How do I close the report after
displaying message?

Thanks,
J.
 
I have
Private Sub Report_NoData(Cancel As Integer)
msgbox ""
docmd.close acform,name

but the close command generates an error. How do I close the report after
displaying message?

Also the msgbox is displayed twice.

Thanks,
J.
 
See answer posted in m.p.a.formscoding where you posted this same question.

Ken Snell
 
That's the line that is generating the error (DoCmd.Close acReport, Name).
Also the msgbox is being displayed twice.
 
Change the entire procedure to this (sorry, I typed my original answer a bit
too quickly):

Private Sub Report_NoData(Cancel As Integer)
Cancel = True
MsgBox "No data"
DoCmd.Close acReport, Me.Name, acSaveNo
End Sub
 
I get
Run-time error '2585':
A macro specified as the onopen, onclose, onformat, onretreat, onpage,
onprint property setting contains an invalid action for the property.
When you click OK, An Action Failed dialog box will display the name of the
macro that failed and its arguments.
 
I now have on form:
On Error Resume Next
DoCmd.OpenReport stDocName, acPreview
on error goto 0

on report:
opencount = opencount + 1
if opencount = 1 then msgbox ""
docmd.cancelevent
 
I've found the error in my code:

I have removed the SQL for the reports data source and just entered the name
of the query.
I already had:
if dlookup(,"queryname",) then
docmd.openreport
else
msgbox ""
endif

the problem was to do with the query. I cut the sql from the report data and
pasted it over the query SQL statement. Now I don't need the nodata code. I
usually handle the no data from the form, then open if if data exists.
 
Back
Top