PDA

View Full Version : Printing "X" number of copies...


rzawora
11-19-2004, 11:35 AM
I have written a macro which replaces the default print command in a template I created. The template contains a macro which checks the default printer changes it to the printer needed for this document, then prints "X" number of copies, changes the printer back to what it was, then closes the document. I have created a userform called printform that pops up when FilePrint is initialized, the box simply asks how many copies they would like to print which they type into a textbox named NumCopies
What code do I use to set the number inputted into the textbox as the variable for how many copies to print?

starl
11-19-2004, 07:40 PM
post the code that you have already, please

rzawora
11-19-2004, 10:38 PM
When viewing the following code, please keep in mind that in my document template there is a form field bookmarked pkgs that is used to set the amount of labels to print now. I'm trying to do away with that, and give the user a dialog box asking them how many labels to print. Currently it prints X number of copies where X equals the amount of packages as they have printed on the labels. This code is from a userform I created named printform in print form there is NumCopiesLabel, NumCopies (textbox), and Print (Command Button). When the user initializes FilePrint it runs a check to make sure the fields are all filled out properly (code not shown) then, when the Print command button is pressed the following code happens. I want to get rid of the iNumCopies variable here and replace it with whatever number is in the NumCopies textbox in the printform UserForm. Let me know if you can help...

Sub FilePrint()

'Runs the following code when the Print Labels button is clicked
Private Sub PrintButton_Click()

Dim iNumCopies As Integer, CurPrinter$, VarResult As Variant

'Acquires current system printer's name so it can re-set when done
CurPrinter$ = ActivePrinter

'Changes the printer to the networked thermal label printer
ActivePrinter = "\\COMPUTER9\Label"

VarResult = ActiveDocument.FormFields("pkgs").Result


iNumCopies = (ActiveDocument.FormFields("pkgs").Result)

'Prints out the defined number of copies
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=iNumCopies, Pages:="", PageType:=wdPrintAllPages

'Now re-set to original printer
ActivePrinter = CurPrinter$

'Unload document
Unload Me

'Clears the document
ActiveDocument.Unprotect
ActiveDocument.ResetFormFields
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

'Sets focus to beginning first form field
ActiveDocument.FormFields("pkgs").Select
End Sub

starl
11-20-2004, 06:14 PM
change
Copies:=iNumCopies

to Copies:= Printform.NumCopies.Value

rzawora
11-22-2004, 10:36 AM
I tried this but I get a compile error at the PrintButton_click when I attempt this. Any other suggestions?

rzawora
11-22-2004, 01:34 PM
Okay, I messed around with this for awhile...
I got the following to work...
Copies:=project.printform.NumCopies.value

Is this the way it should be?

starl
11-23-2004, 10:56 AM
well, if it works :-D
I'm not sure what the "project" is..
admittedly - I find it difficult to program without the actual file(s) in front of me.