VBA Print Button... 2 copies instead of 1?

tim1982

Registered User.
Local time
Today, 09:06
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
 
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
 
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.
 
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
 
Should PrintWOs intNumCopies be PrintWOs(intNumCopies)
as you are passing a parameter?
 
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.
 
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

Back
Top Bottom