VBA Print Button... 2 copies instead of 1? (1 Viewer)

tim1982

Registered User.
Local time
Today, 12:36
Joined
Feb 18, 2009
Messages
21
Hello,

I have a WorkOrder Print Button in a form that I want to print TWO copies instead of the standard one... Could someone help me with where I need to add to my VBA.


Private Sub PrintWorkOrders_Click()

DoCmd.OpenReport "WorkOrders", PrintOut, , _
"[OrderID]=Forms![Enter/Edit Orders].[OrderID]"
Me.[WorkOrderPrint] = True

End Sub


Appreciated,

Tim
 

boblarson

Smeghead
Local time
Today, 12:36
Joined
Jan 12, 2001
Messages
32,059
Just double up on this line:

DoCmd.OpenReport "WorkOrders", PrintOut, , _
"[OrderID]=Forms![Enter/Edit Orders].[OrderID]"


So:

Code:
Private Sub PrintWorkOrders_Click()

DoCmd.OpenReport "WorkOrders", PrintOut, , _
"[OrderID]=Forms![Enter/Edit Orders].[OrderID]"
DoCmd.OpenReport "WorkOrders", PrintOut, , _
"[OrderID]=Forms![Enter/Edit Orders].[OrderID]"

Me.[WorkOrderPrint] = True

End Sub
 

tim1982

Registered User.
Local time
Today, 12:36
Joined
Feb 18, 2009
Messages
21
Haha, excellent.

Thanks a lot, Bob.... Now if I need 10 copies of something, I'll look like I really know how to code in VBA.
 

boblarson

Smeghead
Local time
Today, 12:36
Joined
Jan 12, 2001
Messages
32,059
You can also cycle through by passing the number of copies:

Code:
Function PrintWOs(intCopies As Integer)
Dim intPrint As Integer

For intPrint = 1 to intCopies
    DoCmd.OpenReport "WorkOrders", PrintOut, , _
"[OrderID]=Forms![Enter/Edit Orders].[OrderID]"
Next intPrint

End Function

And then call it like this:

Code:
Private Sub PrintWorkOrders_Click()
Dim intNumCopies As Integer

intNumCopies = InputBox("Enter the Number of Copies to Print", "Number of Copies")

PrintWOs intNumCopies

Me.[WorkOrderPrint] = True

End Sub
 

Poppa Smurf

Registered User.
Local time
Tomorrow, 05:36
Joined
Mar 21, 2008
Messages
448
Should PrintWOs intNumCopies be PrintWOs(intNumCopies)
as you are passing a parameter?
 

boblarson

Smeghead
Local time
Today, 12:36
Joined
Jan 12, 2001
Messages
32,059
Should PrintWOs intNumCopies be PrintWOs(intNumCopies)
as you are passing a parameter?

Nope, because if you try it you will find it chokes. But, if you put the word CALL in there THEN you can include the parens.
 

boblarson

Smeghead
Local time
Today, 12:36
Joined
Jan 12, 2001
Messages
32,059
So, if you do

Call PrintWOs(3)

then you can include the parens

or if you go

Me.ReturnValue = PrintWOs(3)

but if you just use

PrintWOs

then you must call it WITHOUT the parens

PrintWOs 3

As that is the way ALL functions work in VBA.
 

Users who are viewing this thread

Top Bottom