We help IT Professionals succeed at work.

Weird default Printer Problems

Coates
Coates asked
on
174 Views
Last Modified: 2010-04-30
I am trying to select a printer from the printers installed on my machine which happens to be a label printer, and print a few details to it. However, My vb program seems always to print to the default printer no matter what printer i select. I am using the same code as given in the vb help files, but this doesn't seem to work.

Here is the code im using:

Dim ret As Integer
ret = MsgBox("Are You Sure You Want To Print Label?", vbQuestion + vbYesNo, "Print Confirm")
If ret = vbYes Then
'the following code will select the correct printer'
Dim X As Printer
For Each X In Printers
    If X.DeviceName = "Label Printer" Then
        Set Printer = X
        Exit For
   End If
Next X

'Print the details to the printer
Printer.Print "Line 1"
Printer.Print "Line 2"
Printer.Print "Line 3"
Printer.EndDoc

Can anyone see the problem?
When i set the label printer as default, this works fine!
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
re service packs: This is a windows 98 machine, do i need to install the service pack?

Commented:
You need the service Pack 3 of VB or use the function  Win95SetDefaultPrinter wich work under Win95,NT,98.

One better solution is installing SVPack 3 and use anyway the function.

Author

Commented:
I have recently got a copy of VB 6.0. Is a service pack needed for this?

Commented:
I don't think. I have not yet tested VB6.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.