print more than one copy of a report from a form.

M

Michael

I have a form that prints a report using the following code


Private Sub Command67_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox ""
Else
strWhere = "[RintracciabilitàID] = " & Me.[RintracciabilitàID]
DoCmd.OpenReport "Rintracciabilità", acNormal, , strWhere
End If
End Sub

is there a way to add a textbox where the user can put a number for the
amount of copies he would like of this report?
thank you
Michael
 
S

SusanV

Hi Michael,
Sure, add an unbound textbox (txtCopies) for the number of copies to print,
then modify your code to include a loop counting down the number of copies:

Private Sub Command67_Click()

Dim strWhere As String
Dim copies as Integer

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox ""
Else
copies = Me.txtCopies
Do While copies > 0
strWhere = "[RintracciabilitàID] = " & Me.[RintracciabilitàID]
DoCmd.OpenReport "Rintracciabilità", acNormal, , strWhere
copies = copies - 1
Loop

End If
End Sub
 
A

Allen Browne

There are several ways to do this, Michael.

One is to use PrintOut instead of OpenReport
Printout Multiple copies of a report
at:
http://www.mvps.org/access/reports/rpt0001.htm
But this approach does not let you use a WhereCondition, so the workaround
would be to create a global string variable to hold the filter, assign a
value to it immediately before the PrintOut line, and then use the Open
event of the report to see if there is something in the string and if so
apply it as the Filter of the report and clear the string.

A better solution might be the technique described here:
Printing a Quantity of a Label
at:
http://allenbrowne.com/ser-39.html
You create the table to hold the counter, and include this table in the
query that feeds your report. This query causes the report to print multiple
copies, and you can control how many by adding it to the WhereCondition of
OpenReport. Assuming you have a text box named txtHowMany on your form, you
would then need to adjust just the line immediately before "DoCmd.OpenReport
...." to:

strWhere = "([Rintracciabilit`ID] = " & Me.[Rintracciabilit`ID] & _
") AND (CountID <= " & Nz(Me.txtHowMany,1) & ")"
 
M

Michael

thank you very much Susan.
Michael
SusanV said:
Hi Michael,
Sure, add an unbound textbox (txtCopies) for the number of copies to
print, then modify your code to include a loop counting down the number of
copies:

Private Sub Command67_Click()

Dim strWhere As String
Dim copies as Integer

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox ""
Else
copies = Me.txtCopies
Do While copies > 0
strWhere = "[RintracciabilitàID] = " & Me.[RintracciabilitàID]
DoCmd.OpenReport "Rintracciabilità", acNormal, , strWhere
copies = copies - 1
Loop

End If
End Sub
--
hth,
SusanV


Michael said:
I have a form that prints a report using the following code


Private Sub Command67_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox ""
Else
strWhere = "[RintracciabilitàID] = " & Me.[RintracciabilitàID]
DoCmd.OpenReport "Rintracciabilità", acNormal, , strWhere
End If
End Sub

is there a way to add a textbox where the user can put a number for the
amount of copies he would like of this report?
thank you
Michael
 
S

SusanV

Oh, one more thing - you'll probably want to add a line so that if the user
doesn't enter a value in txtCopies it will automatically print one - or set
the default value of the textbox to 1 - either way. Otherwise some l-user
will complain that it "doesn't print"

;-)

SusanV

SusanV said:
Hi Michael,
Sure, add an unbound textbox (txtCopies) for the number of copies to
print, then modify your code to include a loop counting down the number of
copies:

Private Sub Command67_Click()

Dim strWhere As String
Dim copies as Integer

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox ""
Else
copies = Me.txtCopies
Do While copies > 0
strWhere = "[RintracciabilitàID] = " & Me.[RintracciabilitàID]
DoCmd.OpenReport "Rintracciabilità", acNormal, , strWhere
copies = copies - 1
Loop

End If
End Sub
--
hth,
SusanV


Michael said:
I have a form that prints a report using the following code


Private Sub Command67_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox ""
Else
strWhere = "[RintracciabilitàID] = " & Me.[RintracciabilitàID]
DoCmd.OpenReport "Rintracciabilità", acNormal, , strWhere
End If
End Sub

is there a way to add a textbox where the user can put a number for the
amount of copies he would like of this report?
thank you
Michael
 

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