Changing printers in VB
Changing printers in VB
(OP)
I've written a program right now that will print barcodes to a printer. However unless the default printer is set up as the Eltron TLC 2622 (barcode printer), it will not print there. This is a pain b/c if I want to print out a document, I need to change back to my other printer continuously from the Printers in the control panel. Is there any code or way that I can make the one program use the Eltron printer, but have the default printer set up to another printer (like a deskjet)? I've found some code, but its for an excel spreadsheet only and doesn't work.





RE: Changing printers in VB
You can find the available printer names like this:
CODE
For a = 0 to Printers.Count - 1
Debug.Print Printers(a).Devicename
Next a
CODE
To set the default printer once you decide the name:
CODE
If prtDev.DeviceName = "DMP" Then
Set Printer = prtDev
End If
Next
Note that the Printers collection is not available in VBA
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
UK steam enthusiasts: www.essexsteam.co.uk
RE: Changing printers in VB
RE: Changing printers in VB
CODE
Dim prtDev as Printer
Printer.TrackDefault = True
strDefPrtName = Printer.DeviceName
For Each prtDev In Printers
If (prtDev.DeviceName = "<Name of Barcode Printer>") Then
Set Printer = prtDev
End If
Next prtDev
<Print the Bar Code Labels>
For Each prtDev In Printers
If (prtDev.DeviceName = strDefPrtName) Then
Set Printer = prtDev
End If
Next prtDev
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Changing printers in VB
the code
Printer.TrackDefault = True
will cause your program to track default printer, you sholud set it to false so your program will print to your selected device.
if you want to be sure, just save the default and re select it
Printer object has a nice help file in VB6 with examples
also visit
http://
join it is free
all vb codes are catigorised, download what you need to know
another free site
http://www.vbcode.com/
Maged A. Mohamed
http://magedm.freeyellow.com
http://www.magedsoft.com
RE: Changing printers in VB
I was trying to write a program myself in VB for my Eltron printer but am having real difficulties with ELP2. All I want to do is print a bitmap on a label. Could you share some code with me that might solve my problem?
Cheers,
Rob
RE: Changing printers in VB
What my code does is calls a crystal report that I had created with the proper size of the label and margin settings. Then it brings up a preview of the label (in crystal reports) and then when you click print, it prints the label to the default printer, which ends up being the Eltron. Sorry, I don't think that I have any code that'll be benefitial to you. What you might want to do is see if you can find or get a chunk of code that brings up paint or a picture viewer with your bitmap in it with the margins and settings all set up. Then set your Eltron to default and click the print button. Good luck and let me know if it turns out or not.
Brad
RE: Changing printers in VB
The printer is connected properly. Windows Test Page printed to it, and the Eltron Create-A-Label software works fine. If I try to print a bitmap from Paint (say) however, it just ejects blank labels. From my VB.NET program where I create a bitmap to be printed, it prints just a small portion of the desired image down the centre of the label. To try and solve the problem therefore, I've tried to use EPL commands by sending them as raw data to the printer using code from http://support.microsoft.com/?scid=kb;EN-US;322090
, but have only had limited success.
Before explaining any further I guess what I need to ask is Are you familiar with EPL2? and if not, can you think of any way at all (using any software) that I could use to just print an image (bitmap). At least that would be a step in the right direction :)
Thanks again in advance,
Rob
RE: Changing printers in VB
What size are the labels that you are using? Because what might be happening is that if say your label is 1x3 (inches) and you have white space around your bitmap, it may just be printing the white space. Theoretically though, it should just see the Eltron as another printer and print from paint. You can set up the page size/label size, margins and all that from the printer properties(which you already probably know). I'm not familiar with EPL2 language. The printer that I was using was an Eltron 2622/2722. I didn't have to use the PCL for the printer. One thing that you need to watch though is that some of the text MUST BE ASCII
Ex: crsReport1.FormulaFields.Item(1).Text = Chr$(39) & "PO#: " & strPONumber & Chr$(39)
This is just an example of a section of code that I put in. It calls a PONumber and turns it into a barcode, but I needed to use ASCII text in order for it to work (39 = ,).
Another thing that you have to watch is the drivers for the printer and the versions and such with ELP2.
All I can suggest is to try setting margins or somehow setting a border around the image from VB.net. That way you'll be able to see if the image is getting bigger or smaller on the label.
CrystalReportViewer.CRViewer1.Height = 400
CrystalReportViewer.CRViewer1.Width = 600
This code works to size the crystal reports window, so try something like this to size the image to the size of the labels.
Else, if you have a version of photoshop, try printing the label from there. Photoshop has many great features, and you may be able to find what your looking for there. I'll keep thinking about this though, and if I get any other brainwaves I'll let you know.
Keep me posted! :)
Brad
RE: Changing printers in VB
Thanks for all your help. I had a intensive session last night with the printer and managed to crack most all of my problems.
Although I did know about changing margins, I just hadn't thought to do so, and sure enough as soon as I added a PageSetupDialog in my program I was able to tweak and configure my printer correctly. Now the only work I have to do is similar to your original problem :)
I guess the problems I was having with ELP2 just had me sidetracked.
Speaking of which, the way in which my program prints a bitmap onto the printer seems to result in a fair amount of clarity loss, so I tried to persevere with ELP2 in order to create the image I wanted using printer commands alone. As you suspected, some of the text needed to be in ASCII, and I have since managed to get most of the commands to work. Strangely, some work when not in ASCII (which was helping to confuse me earlier, I think) and some dont work even when they ARE in ASCII. Strange...but at least a bulk of the issues are behind me.
Thanks again for your all of your time and help btw. I really do appreciate it.
Cheers,
Rob