code to print multiple copies (1 Viewer)

actionashley

Josey Wales
Local time
Today, 09:38
Joined
Jun 16, 2010
Messages
39
I am keeping track of production in access assigning lot numbers to products.
I need to print labels for bins of products I make. I have created a query to give me the specific lot number I need to print, a form to feed the query and a report to print the labels. My problem is I want to have a control on the form to indicate how many labels to print of each quantity. If I produce 10,500 parts I may need 10 labels at 1000 and 1 at 500 for instance. Currently I have a macro that opens the report in preview mode and I hit print and choose my quantity of labels which works but I want to make it a little more user friendly.

I tried this but it did not work

docmd.PrintOut ,,,,=[forms]![FormName]![ContolName]

Do I need to assign a variable for the number of copies instead of using an expression?
 

Trevor G

Registered User.
Local time
Today, 17:38
Joined
Oct 1, 2009
Messages
2,341
Take a look at this extract.

(Q) How do I printout multiple copies of one report without having to use the Docmd.OpenReport multiple times?
(A) Use the Printout Method of the Docmd object.
DoCmd.PrintOut [printrange][, pagefrom, pageto] _
[, printquality][, copies][, collatecopies]
For example, if I want to print out two copies of the first page of a report, I would use
DoCmd.OpenReport "rptCustomers", acViewPreview
DoCmd.PrintOut acPages, 1, 1, , 2
'Access 2.0 equivalent is Docmd Print
OR as posted by Alex Dybenko, the following method which does not require the report to be in Preview mode.
DoCmd.SelectObject acReport, "rptCustomers", True
'This prints out two copies of the report
DoCmd.PrintOut , , , , 2
'Access 2.0 equivalent is Docmd Print
 

actionashley

Josey Wales
Local time
Today, 09:38
Joined
Jun 16, 2010
Messages
39
Thanks Trevor, how do I get the "2", for 2 copies, to come from a user input form?
 

Trevor G

Registered User.
Local time
Today, 17:38
Joined
Oct 1, 2009
Messages
2,341
What about adding a unbound text box and name it something like txtPrint then refer to the txtPrint in your statement, so if the user wants 2 they type in 2 then click the print button if they want 10 they type in 10 then click the print button

DoCmd.SelectObject acReport, "rptCustomers", True
'This prints out two copies of the report
DoCmd.PrintOut , , , , 2

so the docmd.Printout,,,,txtPrint.value
 

dragofly

Registered User.
Local time
Today, 11:38
Joined
Aug 3, 2010
Messages
23
Leave the equals sign out and try.value and/or CInt() to force it to be an int.
 

actionashley

Josey Wales
Local time
Today, 09:38
Joined
Jun 16, 2010
Messages
39
Thank you D-Fly.

I had 2 problems with my code. 1st I had brackets around the report name and they should have been quotation marks. And I removed the = sign and added .value at the end and it worked!! Here is the code that worked.

DoCmd.OpenReport "LabelShopOrderQuery", acViewPreview

DoCmd.PrintOut , , , , [Forms]![LabelValues]![QuantityInternal].Value

Now I need to insert a message box between the do commands to confirm the printing.

I will post back if I can't figure that out on my own.

Love this forum
 

actionashley

Josey Wales
Local time
Today, 09:38
Joined
Jun 16, 2010
Messages
39
Ok 95% successful

My code
DoCmd.OpenReport "LabelShopOrderQueryGel", acViewPreview
'create the message box
Dim PRNT As Integer
'PRNT = MsgBox("Print" & "[Forms]![LabelValues]![NumLabelsGel].Value" & " Labels?", vbQuestion + vbYesNo + vbDefaultButton1, "Question")
PRNT = MsgBox("Print Labels?", vbQuestion + vbYesNo + vbDefaultButton1, "Question")

If PRNT = vbYes Then

DoCmd.PrintOut , , , , [Forms]![LabelValues]![NumLabelsGel].Value
DoCmd.close

Else
DoCmd.close

End If

The top comment was my attempt to have my message read with the number of labels to print included. Currently it says "Print Labels?" I want "Print 5 Labels?" where 5 is the user input (same as number of copies)
 

dragofly

Registered User.
Local time
Today, 11:38
Joined
Aug 3, 2010
Messages
23
PRNT = MsgBox("Print "&CStr([Forms]![LabelValues]![NumLabelsGel].Value) &" Labels?", vbQuestion + vbYesNo + vbDefaultButton1, "Question")
 

actionashley

Josey Wales
Local time
Today, 09:38
Joined
Jun 16, 2010
Messages
39
Worked like a charm.

So I don't put the value in quotes I use CStr in front.

Can you walk me through why it worked?
 

sumox

Registered User.
Local time
Today, 22:08
Joined
Oct 1, 2013
Messages
89
Re: code to print multiple copies : for invoicing custom labels

What about adding a unbound text box and name it something like txtPrint then refer to the txtPrint in your statement, so if the user wants 2 they type in 2 then click the print button if they want 10 they type in 10 then click the print button



so the docmd.Printout,,,,txtPrint.value

Dear sir,

I want to set a code to print three copy of a Report INVOICE_F
but in different way
I want to message viewers "Printing three copies"
this is not big thing

But the big thing is
I want a Text on rightmost side saying IIF it's first copy then say "Original"
IIF it's second copy then say "Duplicate" and IIF it's third copy then say
"Triplicate"

can u do mix Arrays + docmd.PrintOut + For While loops for
Printing three copies with seperate Text on rightmost side of each copy !

Thanks and Great thanks in advance

Sir, Please Help !:banghead::banghead:
 

Users who are viewing this thread

Top Bottom