Microsoft KB Archive/221780

= PRB: Printer Properties Show Incorrect Values =

Article ID: 221780

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q221780



SYMPTOMS
When you read a printer property, such as Mycopies = Printer.Copies, before you print anything, the results are incorrect. Specifically, the values that are returned do not match what you see when you examine the printer's properties directly.



CAUSE
This behavior occurs because the printer object is not initialized.



Steps to Reproduce Behavior
 Start a new Standard EXE project. Form1 is created by default. Add a CommandButton, a ComboBox, and four TextBox controls to Form1.  In the code window of Form1, paste the following code: Option Explicit Dim MyX As Printer

Private Sub Combo1_Click For Each MyX In Printers If MyX.DeviceName = Combo1.Text Then Set Printer = MyX Exit For End If   Next Text1.Text = Printer.Copies Text2.Text = Printer.DeviceName Text3.Text = Printer.Orientation 'Text4.Text = Printer.CurrentX End Sub

Private Sub Command1_Click Unload Me End Sub

Private Sub Form_Load Dim x As Integer

For x = 0 To Printers.Count - 1 Combo1.AddItem Printers(x).DeviceName Next x   Combo1.Text = Printer.DeviceName

Text1.Text = Printer.Copies Text2.Text = Printer.DeviceName Text3.Text = Printer.Orientation 'Text4.Text = Printer.CurrentX End Sub  Make sure that you have more than one printer installed on the computer, and that the default number of copies and orientation are different for both printers. Save and run the project. When you change selections with Combo1, the value in Text2 changes, but Text1 and Text3 do not change and are therefore incorrect. Text4 is not being used yet. Click Command1 to stop the project.</li></ol>

WORKAROUND

 * 1) Under Combo1_Click and Form1_Load in the preceding code, uncomment the lines that read "Text4.Text = Printer.CurrentX".
 * 2) Save and run the project again. When you change selections with Combo1, the values for the first three TextBoxes change to the correct values. Text4 simply receives the same value each time.

Keywords: kbprint kbprb KB221780

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.