Error 2501

  • Thread starter Thread starter PayeDoc
  • Start date Start date
P

PayeDoc

Hello All

I have a number of reports with the OnNoData event set to Cancel = True.
Normally these reports are opened individually via individual buttons on a
form, and where there is no data for a report it simply doesn't open - which
is fine. I also have a complex procedure, however, which is fired from
another button, and which ends by attempting to open the above-mentioned
reports: but in this case the Cancel = True event seems not to work
properly, in that I get a message (2501) about the open event being
cancelled. This is a real irritation, as the users need to click OK every
time - and frequently ask me/eachother what it means!

Is there a way of cancelling the error 2501 message?

Hope someone can help.

Many thanks
Leslie Isaacs
 
Use error handling. Trap error 2501, and ignore it.

The easiest way to do this is to create a little function that opens the
reports. It suppresses this error, returning True if the report opened and
False if it did not. You can call this function and ignore the return value
if you don't care, or call it and examine the return value if you need to
know.

At the same time, you can solve a couple of other issues with
DoCmd.OpenReport, e.g.:
- default to opening in preview rather than normal;
- skip the useless Filter argument;
- pass a description in OpenArgs, and parse it in your reports.

For an example of a function that does that, see the OpenTheReport() example
here:
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport
 
Hello Allen

Many thanks for your reply: I wasn't expecting such a comprehensive
solution!!

Before I try to use your OpenTheReport function, I just wanted to check that
I will not fall foul of the 1st limitation that is given:
"May not work where multiple reports sent directly to print, without pause."

The current problem ocurrs when I try to print (not preview) the reports at
then end of a fairly long procedure. The code at the end of the procedure is
simply:
DoCmd.OpenReport "rpt COMPARE SUMMARY", acNormal
DoCmd.OpenReport "rpt check taxable etc", acNormal
DoCmd.OpenReport "rpt changed basics", acNormal
DoCmd.OpenReport "rpt changes to normals", acNormal
etc.

Presumably I would need to replace these with
OpenTheReport ("rpt COMPARE SUMMARY")
OpenTheReport ("rpt check taxable etc")
OpenTheReport ("rpt changed basics")
OpenTheReport ("rpt changes to normals")
etc.

and I would need to replace
Function OpenTheReport(strDoc As String, _
Optional lngView As AcView = acViewPreview, _
Optional strWhere As String, _
Optional strDescrip As String, _
Optional lngWindowMode As AcWindowMode = acWindowNormal) As Boolean
with
Function OpenTheReport(strDoc As String, _
Optional lngView As AcView = acViewNormal, _
Optional strWhere As String, _
Optional strDescrip As String, _
Optional lngWindowMode As AcWindowMode = acWindowNormal) As Boolean

But what about that limitation? Is there a workaround?

Thanks again for the help.
Les
 
From memory, the problem referred to is where you try to print the same
report multiple times, so probably won't apply 2 u.

Yes, you call your report with:
Call OpenTheReport("rpt COMPARE SUMMARY", acViewNormal)
etc

You don't have to modify the default view of you specify it like that.
 
Hello Allen

I'm afraid I can't get this to work: I keep getting a compile error - "Wrong
number of arguments or invalid property assignment", with the code halting
on the line
DoCmd.OpenReport strDoc, lngView, , strWhere, lngWindowMode, strDescrip
with the 'OpenReport ' part highlighted..

I had copied the entire code from
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport
into a new module. When I first got the compile error, I tried removing the
one of the two commas between 'lngView' and 'strWhere' (in case this was why
an extra parameter was expected, but that didn't help, so I tried swapping
'lngWindowMode' and 'strDescrip' in the DoCmd.OpenReport line - because they
seemed (to me!) to be specified the other way round in the initial
declaration of the function:
Function OpenTheReport(strDoc As String, _
Optional lngView As AcView = acViewPreview, _
Optional strWhere As String, _
Optional strDescrip As String, _
Optional lngWindowMode As AcWindowMode = acWindowNormal) As Boolean

Needless to say, that didn't work either!!

Where have I gone wrong?
Also, do I really need all the functions (SetupPrinter4Report, UsePrinter,
etc.) for OpenTheReport to work?

Thanks again for your help.
Les
 
1. Copy the code exactly as is, and post into a standard module.

2. Save the module with a name such as ajbReport. (It can't be the same as
the function name.)

3. To verify that Access understands it, choose Compiled on the Debug menu.
(It compiles and greys out unless there are errors you must fix.)

4. Call it as indicated, i.e.:
Call OpenTheReport("rpt COMPARE SUMMARY", acViewNormal)
 
Hello Allen

With all the code re-pasted in from your website and doing Debug>Compile, I
get the same compile error:
"Wrong number of arguments or invalid property assignment"
with the code halting on the line
DoCmd.OpenReport strDoc, lngView, , strWhere, lngWindowMode, strDescrip
with the 'OpenReport ' part highlighted.

Unfortunately I am away for 2 week from tomorrow, so will be unable to try
anything you suggest until after that (unless you reply to this in the next
hour or so!). I do very much apppreciate your help - just wish I knew more
about this stuff so could identify and fix the error myself.

I'll check here in an hour, and then when I'm back in 2 weeks.

Thanks again
Les
 
What version of Access is this?

As the article points out, Access 2000 doesn't have the OpenArgs, so you
will need to drop the strdescrip.
 
Back
Top