no-record report-msg & then close?

  • Thread starter Shivalee Gupta via AccessMonster.com
  • Start date
S

Shivalee Gupta via AccessMonster.com

I have a report which opens a parameter query. If the query is returning 0
(zero) rows, there should be a message saying "no rows returned" and then
the empty report should not open, I mean nothing should happen after that.
In the report, I went to "ON NO DATA" and I wrote:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "sorry"
DoCmd.Close
End Sub

These lines give me an error:

Run-Time error:2585.
The action can't be carried out while processing a form or report event.

What am I doing wrong?
Can anybody help me?
thanks
shivalee
 
B

Brendan Reynolds

Take out the 'DoCmd.Close' line and add ...
Cancel = True
.... to cancel the opening of the report. You'll also need to trap the 'you
cancelled the action' error (error number 2501) that will be raised in the
code that opened the report.
 
S

Shivalee Gupta via AccessMonster.com

I have tried your code and it works fine. but after my msgbox is displayed,
it displays me this message saying:

The OpenReport action was cancelled.

Can't I remove this messagebox also?
Any suggestions?
Thanks,
shivalee
 
D

Duane Hookom

Brendan provided the solution to this error. Please re-read and then come on
back if you have a question. I expect if you search google on your error
message and the number he mentioned, you will find some code.
 
B

Brendan Reynolds

<quote>
You'll also need to trap the 'you
cancelled the action' error (error number 2501) that will be raised in the
code that opened the report.
</quote>

Your error handler will need to look something like ...

If Err.Number = 2501 Then
'do nothing
Else
'whatever you want to do when an unanticipated error occurs
End If
 
S

Shivalee Gupta via AccessMonster.com

Duane there was no reason to be so rude.
brendan, i changed the sub as follows:

Private Sub show_tcodes_from_uname_report_Click()
On Error GoTo Err_show_tcodes_from_uname_report_Click

Dim stDocName As String
stDocName = "displaying Tcodes from uname"
DoCmd.OpenReport stDocName, acPreview

Exit_show_tcodes_from_uname_report_Click:
Exit Sub

Err_show_tcodes_from_uname_report_Click:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_show_tcodes_from_uname_report_Click

End Sub

ANd now it is running.
thanks both of you,
shivalee.
 

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