Click here to Skip to main content
15,867,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day experts, i just want to ask if there is a way to print a report (which is a receipt) in two printer at the same time.? i managed to print a single report but i never tried printing it in two similar printer name,and i'm a little bit confused to that. this is my code in printing a single receipt:

VB
Public Sub printing()
        Dim rpt As New orderrpt() 'The report you created.
        Dim MyCommand As New SqlCommand()
        Dim myDA As New SqlDataAdapter()
        Dim myDS As New DataSet1() 'The DataSet you created.
        Dim cn As New SqlConnection(ConnectString())

        Try

            MyCommand.Connection = cn
            MyCommand.CommandText = "SELECT * FROM foodordertbl where foilionum=" + folioid
            MyCommand.CommandType = CommandType.Text
            myDA.SelectCommand = MyCommand
            myDA.Fill(myDS, "foodordertbl")

            myDS.EnforceConstraints = False
            rpt.SetDataSource(myDS)
            CrystalReportViewer1.ReportSource = rpt
            rpt.PrintOptions.PrinterName = "EPSON TM-T88IV Receipt"
            rpt.PrintToPrinter(1, False, 0, 0)
        Catch Excep As Exception
            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
            MessageBoxIcon.Error)
        End Try

    End Sub

i hope anyone of you here have an idea or suggestion regarding to my problem.thanks a lot!
Posted
Updated 25-Jun-13 15:06pm
v2

1 solution

Could you not simply reset the printer name and printtoprinter it again? It won't be at exactly the same time, but near enough.

Apart from that, hardcoding a printer name into your code is a very bad idea. You would be better to set this in a config file so it can be easily updated as required (without a recompile).
 
Share this answer
 
Comments
Chester Costa 25-Jun-13 21:28pm    
sorry sir but i do not know how to set that code in config file. anyway, i need to print the reports in two printer,the first printer is connected to the cashier while the other one is connected to the kitchen by using a printer server.how am i to do that?
_Damian S_ 25-Jun-13 21:33pm    
Both printers need to be available to the system printing the order. Use the same code you already have (that you said was working), but replace the printer name with the name of the second printer.
Chester Costa 25-Jun-13 21:39pm    
so is it possible to do that sir with the same printer name?i'll try the same code
_Damian S_ 25-Jun-13 21:40pm    
You can't have two printers on the same system with the same name... Use the two different names, even if they are the same type of printer...
Chester Costa 25-Jun-13 22:40pm    
i just found out that the name of my 2nd printer is "EPSON TM-T88IV ReceiptE4" and the first one is "EPSON TM-T88IV Receipt".i'm goint to try this code like this:

Public Sub printing()
Dim rpt As New orderrpt() 'The report you created.
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New DataSet1() 'The DataSet you created.
Dim cn As New SqlConnection(ConnectString())

Try

MyCommand.Connection = cn
MyCommand.CommandText = "SELECT * FROM foodordertbl where foilionum=" + folioid
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "foodordertbl")

myDS.EnforceConstraints = False
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
rpt.PrintOptions.PrinterName = "EPSON TM-T88IV Receipt"
rpt.PrintOptions.PrinterName = "EPSON TM-T88IV ReceiptE4"
rpt.PrintToPrinter(1, False, 0, 0)
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900