Printing selected number of reports from Command Button

P

PK

I have a command button linked to a (label) report, via a query, displayed on
a Form. The query prompts for a unique record to be selected. I would like
the command button to request the number of copies required rather than just
print one label. Believe it's something connected to an Input Box. Current
Command Button coding as follows:

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Frm_injection_label"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command59_Click:
Exit Sub

Err_Command59_Click:
MsgBox Err.Description
Resume Exit_Command59_Click

End Sub

Any help greatly appreciated. First time user of this site.
 
M

Marshall Barton

PK said:
I have a command button linked to a (label) report, via a query, displayed on
a Form. The query prompts for a unique record to be selected. I would like
the command button to request the number of copies required rather than just
print one label. Believe it's something connected to an Input Box. Current
Command Button coding as follows:

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Frm_injection_label"
DoCmd.OpenForm stDocName, , , stLinkCriteria


I think the best way to do this kind of thing is to first
create a general purpose table named Numbers with one field
named Num. Populate the table with values 1, 2, 3, ... up
to more than you will ever need.

Then create a query to use as the report's record source:

SELECT yourtable.*, Numbers.Num
FROM yourtable, Numbers

Then add an unbound text box named txtCopies to your form
for users to enter the number of copies.

With all that in place, the command button's code would only
need one more line (above the Docmd line):

stLinkCriteria = "Num <= " & Me.txtCopies
 
P

PK

I have followed the instructions but the report always prints the maximum
number of copies that appear in the general purpose Table named Numbers.
Ignores the number i key in txtCopies. Any idea what I may be doing wrong?
Many many thanks.
 
M

Marshall Barton

PK said:
I have followed the instructions but the report always prints the maximum
number of copies that appear in the general purpose Table named Numbers.
Ignores the number i key in txtCopies.


It sounds like you forgot to add the line of code:
stLinkCriteria = "Num <= " & Me.txtCopies
or you added it after the OpenReport line
or you made a mistake retyping the line
or the Num is spelled differently in the table/query/code
 
P

PK

Hi,

Thanks for the second response. I have double checked everything and all
spelling and location of tect looks OK. This is the code from the query:
SELECT Tbl_Numbers.Num
FROM Tbl_Numbers;

and this is the code from the command button:
Private Sub Command79_Click()
On Error GoTo Err_Command79_Click

Dim stDocName As String

stDocName = "Labels_std_micron_filter"
stLinkCriteria = "Num <=" & Me.txtCopies
DoCmd.OpenReport stDocName, acNormal

Exit_Command79_Click:
Exit Sub

Err_Command79_Click:
MsgBox Err.Description
Resume Exit_Command79_Click

End Sub

The text box is unbound and named txtCopies

Any ideas? Still printing as many copies as is the highest number in
Tbl_Numbers

Thanks,
 
M

Marshall Barton

PK said:
Thanks for the second response. I have double checked everything and all
spelling and location of tect looks OK. This is the code from the query:
SELECT Tbl_Numbers.Num
FROM Tbl_Numbers;


Everything else looks ok, but where did that query come
from? You need to use the query I posted (with the real
table name) as the report's record source.
 
P

PK

Works perfectly now. Thanks.
--
PK wilts


Marshall Barton said:
Everything else looks ok, but where did that query come
from? You need to use the query I posted (with the real
table name) as the report's record source.
 

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