[RESOLVED] Print data report on non-default printer-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] Print data report on non-default printer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2012
    Posts
    86

    Resolved [RESOLVED] Print data report on non-default printer

    I need to automatically print datareport on non-default printer.
    Mi default printer is 'Hp 1020'

    Datareporty need to print to a printer \\Tmk_print_serve\lp1

    When I run my code so datareport default printer and print a test text prints the correct printer. How is it possible? Why not print only on one printer?

    What code should I use to datareport printed on: \\Tmk_print_serve\lp1


    DataReport1.Show

    Dim prt As Printer
    For Each prt In Printers
    If prt.DeviceName = "\\Tmk_print_serve\lp1" Then
    Set Printer = prt
    Exit For
    End If
    Next

    DataReport1.PrintReport
    Printer.Print "test"

    Thx

  2. #2

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    8,382

    Re: Print data report on non-default printer

    Never used the data report but is there an option to set the printer as part of the report properties?
    Been a while since I needed to do this and can't remember for sure how I did it but it was either by setting the VB Printer object to the desired printer or perhaps my report tool has an option to set the printer for the report.

    You should not need to modify the windows default printer in any way to do this.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2012
    Posts
    86

    Re: Print data report on non-default printer

    Please try to remember it's important to me.
    Prints all the string datareportu datareport but still prints on the default printer.

    For now, I'll try to change the system printer.

    Thx RhinoBull

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    8,382

    Re: Print data report on non-default printer

    Looking at your code in the first post I think you solution may be as simple as moving some code around. Try setting the printer before you load the report. In the code posted you are showing the report and then changing the printer. I can't be sure about the data report tool but the report engine I use will work with the VB printer object that is active at the time the report is loaded. It will format the report based on this printer object and if you tell it to print without prompting for the printer to use then it will use the printer that was active when the report was loaded.

    Code:
    
    Dim prt As Printer
    For Each prt In Printers
       If prt.DeviceName = "\\Tmk_print_serve\lp1" Then
          Set Printer = prt
          Exit For
       End If
    Next
    DataReport1.Show
    DataReport1.PrintReport
    Printer.Print "test"

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2012
    Posts
    86

    Re: Print data report on non-default printer

    RESOLVED!

    Private Declare Function SetDefaultPrinter Lib "winspool.drv" Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long


    Dim PrintData As Printer
    Dim defprinterpos As Integer

    For Each PrintData In Printers

    If PrintData.DeviceName = Printer.DeviceName Then
    sys_default_printer = Printer.DeviceName
    End If

    Next


    REM ... DATAREPORT CODE ...
    REM ... DATAREPORT CODE ...
    REM ... DATAREPORT CODE ...



    Dim docasna_tiskarna As String
    docasna_tiskarna = "\\Tmk_print_serve\lp1"

    SetDefaultPrinter docasna_tiskarna 'REM API SetDefaultPrinter

    DataReport1.PrintReport

    SetDefaultPrinter sys_default_printer 'REM API SetDefaultPrinter -- back sys.def.printer


    rem THX ALL

  7. #7
    New Member
    Join Date
    May 2014
    Posts
    1

    Re: [RESOLVED] Print data report on non-default printer

    Thanks for this answer Tomasek-TMK , works greate!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.