Print copies of report based on text box

itownson1

Registered User.
Local time
Today, 06:08
Joined
Mar 20, 2019
Messages
43
Hello All

I am printing a report (which is a label) from a form using the command button.
What I want to do is have a text box on the form, so the user can input how many labels are to be printed.
My code so far is:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "RLabelGoodsIn", acViewNormal, , ""[DeliveryID]=" & Me![DeliveryID]
Do.Cmd.Close acForm, "FGoodsIn"

I have tried (DoCmd.Printout Text50.Value) and other variations but it prints the report once and then prints the form.
Is the VBA running to quickly?

Can anybody help on this.
 
You can have the OpenReport line within a For/Next loop that gets the upper value from your textbox.
 
I believe you can specify the print count as a .Printout parameter:

DoCmd.PrintOut printrange, pagefrom, pageto, printquality, copies, collatecopies

I suspect that means you don't open the report acNormal.
If you don't need to see it, AFAIK you don't have to open it at all but never having done this, I'm not certain.
 
As an alternative approach you can open the report in print preview mode then use the PrintOut method to get the desired number of copies then close it, something like ;

Code:
        DoCmd.OpenReport "RLabelGoodsIn", acViewPreview, , "[DeliveryID]=" & Me![DeliveryID]
        DoCmd.PrintOut acPages, , , , Nz(Me.Text50,1)
        DoCmd.Close acReport, "RLabelGoodsIn"

The Nz bit accommodates a missing entry.
 
Excellent guys, really appreciate it.
Minty, tried your way first and it worked perfectly.
I'm sure I'll be back again soon, scratching my head.
 

Users who are viewing this thread

Back
Top Bottom