Results 1 to 3 of 3

Thread: My Code always Prints to the Default Printer (Help)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Posts
    93
    This code works good except it only prints to the default printer. Can Someone Help me. It prints out a picture.

    Private Sub Command2_Click()
    On Error GoTo ErrHandler

    MainFrm.CommonDialog1.Flags = cdlPDNoSelection Or _
    cdlPDNoPageNums Or _
    cdlPDHidePrintToFile Or _
    cdlPDUseDevModeCopies

    MainFrm.CommonDialog1.PrinterDefault = False
    MainFrm.CommonDialog1.CancelError = True
    MainFrm.CommonDialog1.ShowPrinter

    Printer.Copies = MainFrm.CommonDialog1.Copies
    Printer.Orientation = MainFrm.CommonDialog1.Orientation
    Printer.Print ""
    Printer.Print ""
    Printer.Print Tab(12);
    Printer.Print Label2.Caption
    Printer.Print Tab(12);
    Printer.Print Label3.Caption
    Printer.PaintPicture Image1.Picture, 1000, 1000
    Printer.EndDoc
    Exit Sub

    ErrHandler:
    Dim RetVal As Integer
    RetVal = MsgBox("Canceling Print Job", 0, "Printer ")
    Exit Sub

    End Sub

    Thanks
    Brandon

  2. #2
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    This is what I used to show printers you can choose from.

    CommonDialog1.cancelerror = true
    CommonDialog1.flags = cdlpdallpages + cdlpdreturndc
    commondialog1.showprinter

    Just put this in your command2_click procedure.

    good luck

    jeffro

  3. #3
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    instead of using the printer object/control
    use the printerS collection...


    the text below is from the vb helpfile.......

    The Printer object enables you to communicate with a system printer (initially the default system printer).
    The Printers collection enables you to gather information about all the available printers on the system.

    Syntax

    Printer
    Printers(index)

    The index placeholder represents an integer with a range from 0 to Printers.Count-1.

    Remarks

    Use graphics methods to draw text and graphics on the Printer object. Once the Printer object contains the output you want to print, you can use the EndDoc method to send the output directly to the default printer for the application.

    You should check and possibly revise the layout of your forms if you print them. If you use the PrintForm method to print a form, for example, graphical images may be clipped at the bottom of the page and text carried over to the next page.

    The Printers collection enables you to query the available printers so you can specify a default printer for your application. For example, you may want to find out which of the available printers uses a specific printer driver. The following code searches all available printers to locate the first printer with its page orientation set to portrait, then sets it as the default printer:
    Code:
    Dim X As Printer
    For Each X In Printers
    	If X.Orientation = vbPRORPortrait Then
    		' Set printer as system default.
    		Set Printer = X
    		' Stop looking for a printer.
    		Exit For
    	End If
    Next
    You designate one of the printers in the Printers collection as the default printer by using the Set statement. The preceding example designates the printer identified by the object variable X, the default printer for the application.

    Note If you use the Printers collection to specify a particular printer, as in Printers(3), you can only access properties on a read-only basis. To both read and write the properties of an individual printer, you must first make that printer the default printer for the application.
    DocZaf
    {;->

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width