Views:

Product: LABELVIEW, CODESOFT
Version: LABELVIEW Gold and CODESOFT Enterprise 2014 and Newer

This article explains how to populate a printer selection list using a VB Script and automatically switch the active printer when a user selects a printer from a When Printed variable.

Prerequisite: A When Printed variable named Printer must exist on the label.


Create the Printer Selection List

1. Create a new label and add a When Printed variable named Printer.

2. Right-click the label and select Document Properties.

3. Open the VB Script tab, select the OnAfterLoad subroutine, and paste the following VB Script:

dim printerList, printer, i 
Document.Variables.Item("Printer").PickListUse = true 
set printerList = Document.Variables.Item("Printer").GetPickList

for i = 0 to printerList.GetSize 
printerList.DeleteValue 
next

for each printer in Application.PrinterSystem.Printers
printerList.AddValue printer 

next 
Document.Variables.Item("Printer").ValueFromPickList = true

4. Click OK. Then open the Properties for the Printer When Printed variable.


Automatically Switch Printers

5. In the OnChangeFieldData subroutine, add the following VB Script:
Document.Printer.SwitchTo Value

6. Click OK, save the label, close it, and reopen it.
7. When you print the label, the Printer variable will display a list of available printers. Selecting a printer automatically changes the active printer used for printing.