Close report that has no data

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.
 
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?

Also the msgbox is displayed twice.

Thanks,
J.
 
K

Ken Snell \(MVP\)

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

Ken Snell
 
J

Jason

That's the line that is generating the error (DoCmd.Close acReport, Name).
Also the msgbox is being displayed twice.
 
K

Ken Snell \(MVP\)

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
 
J

Jason

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.
 
J

Jason

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
 
J

Jason

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.
 

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

Top