Problem with Pages property of a report

J

jameswfrost

Hi,

I'm attempting to fix some problems in an Access database that was
created by somebody else. It's used solely for printing reports for
records from an external database.

The Access database I'm editing a module named DAOPrintFunctions - I'm
not sure where it came from, but I presume it wasn't written by the
person who put together the Access application. This is where the
trouble lies.

When you print a report, the DAOPrintFunctions module prints the first
page of the report on letterheaded paper (from tray 1 of our printer)
and the remaining pages on blank paper (from tray 2). DAOPrintFunctions
has a function named TwoBinPrint, which is used to do this.

However, if the report has only one page, DAOPrintFunctions still tries
to print the remaining pages. This results in a blank page being
printed between single page reports. The blank page contains nothing
except the letters IB in the top corner. As the majority of reports we
print are single page, this creates a lot of extra work as we have to
manually remove all the blank pages.

I've narrowed down the error to this section of code:


If intDlgReturn = True Then
DoCmd.SelectObject acReport, strRptName
If FirstPage = True Then
DoCmd.PrintOut acPages, 1, 1, , intPassCopies, -1
Else
DoCmd.PrintOut acPages, 2, 9999, , intPassCopies, -1
End If
End If

So I tried inserting an IF to check whether there was more than one
page in the report. If there was, I told it to print. However, I can't
get this to work. I added:

"If Reports(strRptName).Pages > 1 Then" before the line "DoCmd.PrintOut
acPages, 2, 9999, , intPassCopies, -1"

I'm getting an error on the 'Reports(strRptName).Pages' section, saying
"You have entered an an expression that has an invalid reference". And
before you ask, I have added a textbox into the Footer of the report
with the control source =[Pages].

So, after all that - does anybody have any idea why I can't use the
pages variable? Or how I could sort this problem?

I hope someone can help,

Thanks,

James Frost
 
J

John Spencer (MVP)

Unfortunately, the PAGES variable is not populated or even available until the
report is opened for printing/viewing and the report has had a chance to run all
the way to the end to calculate the value of pages. So you cannot use the
values of pages at this point to determine if there is more than one page to print.

From the information provided, I don't see a way to handle this situation.
Perhaps, if a report is ALWAYS a single page, you could pass a value into the
TwoBinPrint function to tell it that this is a one-page report. On the other
hand, if it is ALWAYS a single page report, then you really don't need to call
the function at all if you've set it up to print from the letterhead bin.
Hi,

I'm attempting to fix some problems in an Access database that was
created by somebody else. It's used solely for printing reports for
records from an external database.

The Access database I'm editing a module named DAOPrintFunctions - I'm
not sure where it came from, but I presume it wasn't written by the
person who put together the Access application. This is where the
trouble lies.

When you print a report, the DAOPrintFunctions module prints the first
page of the report on letterheaded paper (from tray 1 of our printer)
and the remaining pages on blank paper (from tray 2). DAOPrintFunctions
has a function named TwoBinPrint, which is used to do this.

However, if the report has only one page, DAOPrintFunctions still tries
to print the remaining pages. This results in a blank page being
printed between single page reports. The blank page contains nothing
except the letters IB in the top corner. As the majority of reports we
print are single page, this creates a lot of extra work as we have to
manually remove all the blank pages.

I've narrowed down the error to this section of code:

If intDlgReturn = True Then
DoCmd.SelectObject acReport, strRptName
If FirstPage = True Then
DoCmd.PrintOut acPages, 1, 1, , intPassCopies, -1
Else
DoCmd.PrintOut acPages, 2, 9999, , intPassCopies, -1
End If
End If

So I tried inserting an IF to check whether there was more than one
page in the report. If there was, I told it to print. However, I can't
get this to work. I added:

"If Reports(strRptName).Pages > 1 Then" before the line "DoCmd.PrintOut
acPages, 2, 9999, , intPassCopies, -1"

I'm getting an error on the 'Reports(strRptName).Pages' section, saying
"You have entered an an expression that has an invalid reference". And
before you ask, I have added a textbox into the Footer of the report
with the control source =[Pages].

So, after all that - does anybody have any idea why I can't use the
pages variable? Or how I could sort this problem?

I hope someone can help,

Thanks,

James Frost
 

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