Print copies of report based on text box (1 Viewer)

itownson1

Registered User.
Local time
Yesterday, 19:31
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:31
Joined
Aug 30, 2003
Messages
36,124
You can have the OpenReport line within a For/Next loop that gets the upper value from your textbox.
 

Micron

AWF VIP
Local time
Yesterday, 22:31
Joined
Oct 20, 2018
Messages
3,478
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.
 

Minty

AWF VIP
Local time
Today, 03:31
Joined
Jul 26, 2013
Messages
10,368
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.
 

itownson1

Registered User.
Local time
Yesterday, 19:31
Joined
Mar 20, 2019
Messages
43
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

Top Bottom