473,473 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Printing to Zebra LP2824

4 New Member
Hello,
I have been using MS Access for quite some time. I am mostly self taught and rely heavily on if..then, and do while...loop statements and occassionaly search for help on these websites if I need something fancy. This has been quite effective and I have been able to produce very helpful databases. However, I have been working on a Point of Sale program recently and I need to print labels to my Zebra LP2824. This printer was used with our previous point of sale and worked fine. I know it still prints because if I hold line-feed when turning it on, it will print the configuration.

However, when I am running code that I found here and many other sites I just can't seem to get any output. None whatsoever. It does spool the file and I notice it in the zebra window when i pause printing. I am unable to get a test page to print for it however. But, I am able to get a test file to print for my canon desktop printer yet the code still doesn't print to it either. So I am kinda at a loss and was hoping perhaps someone could hold my hand through this task.

I am using generic/text only driver as the company that we were using for point of sale said it was necessary. The most recent code I have been working on is from this site and looks like this....Honestly I don't understand much of it, but that has never stopped me from successfully using code that I have found online. A friend of mine mentioned i might need to update the printers firmware...could that be the problem?

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Type DOCINFO
  3. pDocName As String
  4. pOutputFile As String
  5. pDatatype As String
  6. End Type
  7.  
  8. Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
  9. hPrinter As Long) As Long
  10. Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
  11. hPrinter As Long) As Long
  12. Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
  13. hPrinter As Long) As Long
  14. Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
  15. "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
  16. ByVal pDefault As Long) As Long
  17. Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
  18. "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
  19. pDocInfo As DOCINFO) As Long
  20. Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
  21. hPrinter As Long) As Long
  22. Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
  23. hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
  24. pcWritten As Long) As Long
  25.  
  26. Private Sub Command8_Click()
  27. Dim lhPrinter As Long
  28. Dim lReturn As Long
  29. Dim lpcWritten As Long
  30. Dim lDoc As Long
  31.  
  32.  
  33. Dim sWrittenData, sBatchID As String
  34. Dim strLine1, strLine2, strLine3 As String
  35. Dim MyDocInfo As DOCINFO
  36. Dim b() As Byte
  37. lReturn = OpenPrinter("canon", lhPrinter, 0)
  38. If lReturn = 0 Then
  39. MsgBox "The Printer Name you typed wasn't recognized."
  40. Exit Sub
  41. End If
  42. sBatchID = InputBox("Enter the batchID for which labels will be printed", "BatchID", 1)
  43. MyDocInfo.pDocName = "AAAAAA"
  44. MyDocInfo.pOutputFile = vbNullString
  45. MyDocInfo.pDatatype = vbNullString
  46. lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
  47. Call StartPagePrinter(lhPrinter)
  48. strLine1 = "^XA^CFD~SD30^FS" 'indicates start of label, and sets darkness to 30
  49. strLine2 = strLine1 & "^BY2,3,10^A0N,30,36^BCN,50,Y,N,N,N^FO20,40^FD " & "40600005" & "^FS"
  50. 'strLine1 = "B190,30,0,1A,3,4,55,B,""" & "456323" & """" this was a test from another site I found with zpl language i tried to add to this one when it didn't work
  51. strLine3 = strLine2 & "^PQ5^XZ" '^PQ5 would print 5 copies of the Label
  52.  
  53. 'MsgBox "string3 to be written is " & strLine3 ' shows what the string looks like
  54. 'sWrittenData = "B190,30,0,1A,3,4,55,B,""" & "456323" & """" & vbFormFeed
  55. 'MsgBox "Length of string to printer is " & Len(sWrittenData)
  56. 'tells me how long the string is
  57. 'MsgBox "string to be written is " & sWrittenData 'shows what the string looks like that will actually be printed
  58. sWrittenData = strLine3 & vbFormFeed
  59.  
  60. b = StrConv(sWrittenData, vbFromUnicode)
  61.  
  62. lReturn = WritePrinter(lhPrinter, b(0), UBound(b) + 1, lpcWritten)
  63.  
  64. 'lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
  65. lReturn = EndPagePrinter(lhPrinter)
  66. lReturn = EndDocPrinter(lhPrinter)
  67. lReturn = ClosePrinter(lhPrinter)
  68. End Sub
please please help!

PS. Oh yeah....I am using Access 2007-2010.
Jan 16 '12 #1

✓ answered by NeoPa

You're a new user, so I'll try to be gentle.

Before posting code check out When Posting (VBA or SQL) Code. It will help you do things the right way which will save time for you too, as well as make it easier for us to help you. Also consider when posting code, that including lines that have already been commented out indicating they are not required helps no-one (Not us nor you). Time spent preparing a question can make so much difference to how likely you are to get a helpful answer.

In this case, the problem is barely even related to the code I guess, and is more likely either something in the printer setup on the individual PC or the printer itself (This might include some of the literal data sent to the printer but we would need intimate knowledge of the printer in order to help with this, or even recognise what might be causing your issue).

I applaud you for you ingenuity in being able to make such good use of the resources available to you, but your not being the author of the code leaves you unable to explain much that we would almost certainly need to be informed of about what it's doing in order to assist.

Little good news I know, but I suspect and hope that doesn't put you off from asking other questions when you have the need. Not all questions will be as unlikely to find help as this one I suspect.

Good luck anyway :-)

7 6638
NeoPa
32,556 Recognized Expert Moderator MVP
You're a new user, so I'll try to be gentle.

Before posting code check out When Posting (VBA or SQL) Code. It will help you do things the right way which will save time for you too, as well as make it easier for us to help you. Also consider when posting code, that including lines that have already been commented out indicating they are not required helps no-one (Not us nor you). Time spent preparing a question can make so much difference to how likely you are to get a helpful answer.

In this case, the problem is barely even related to the code I guess, and is more likely either something in the printer setup on the individual PC or the printer itself (This might include some of the literal data sent to the printer but we would need intimate knowledge of the printer in order to help with this, or even recognise what might be causing your issue).

I applaud you for you ingenuity in being able to make such good use of the resources available to you, but your not being the author of the code leaves you unable to explain much that we would almost certainly need to be informed of about what it's doing in order to assist.

Little good news I know, but I suspect and hope that doesn't put you off from asking other questions when you have the need. Not all questions will be as unlikely to find help as this one I suspect.

Good luck anyway :-)
Jan 16 '12 #2
cwebb
4 New Member
Hello NeoPa,

Thank you for being gentle. I will try to have my post properly edited next time. It helps to know that the problem is likely with the printer and not the code. There are no errors in the code that stop it from running, but I wasn't sure since I can't even get the desktop printer to print anything. The file does spool though, so makes me think it is being sent to the printer, but the printer can not understand what I am asking it to do.

Thanks,
Cwebb
Jan 16 '12 #3
NeoPa
32,556 Recognized Expert Moderator MVP
This is off Access now, but does the spool go to the printer but never finish, or does it fail ever even to start?

BTW I'm not actually saying that the fix is not associated with the code somewhere, just that the expertise you need is not that of a typical Access expert, but more requires knowledge of the specific printer and/or maybe of the printing systems of Windows.
Jan 16 '12 #4
cwebb
4 New Member
Hello NeoPa,

Thank you for your continued efforts to assist me. I was able to solve my problem. Your initial response was correct. The code did send the batch to the printer; I just was using ZPL instead of EPL printer language and even when I was using EPL, I had some errors.

After messing with the format of the printer commands I have been able to successfully format it and the printer is working wonderfully. I needed to remove the space I had in quotes just before the data to be sent and I also needed to include the chr(34). In addition, I needed to include the vbCrLf commands. It helped me to concatenate the entire file into one line of code, but that just might have been me.

Anyway, here is the formatting that worked for me:

Expand|Select|Wrap|Line Numbers
  1. sWrittenData = "N" & vbCrLf & "B30,30,0,1A,1,2,55,B," & _
  2. Chr(34) & e & Chr(34) & vbCrLf & "A30,135,0,1,1,1,N," & _
  3. Chr(34) & w & Chr(34) & vbCrLf & "A240,30,0,1,3,6,N," & _
  4. Chr(34) & y & Chr(34) & vbCrLf & "P1" & vbCrLf 
  5.  
Thanks again,
cwebb
Jan 18 '12 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Nice :-)

Let me see if I can help you make that a little easier to read and work with. You probably understand by now how important that is, having fallen over the confusion of it earlier :
Expand|Select|Wrap|Line Numbers
  1. sWrittenData = "N%L" & _
  2.                "B30,30,0,1A,1,2,55,B,""" & e & """%L" & _
  3.                "A30,135,0,1,1,1,N,""" & w & """%L" & _
  4.                "A240,30,0,1,3,6,N,""" & y & """%L" & _
  5.                "P1%L"
  6. sWrittenData = Replace(sWrittenData, "%L", vbCrLf)
NB. A double-quote character (") can be written within a string in VBA as two of them (""). VBA resolves this for you. It's actually easier to read and understand than having Chr(34) dotted around your code. You can look up Replace() in Context-Sensitive Help, but it this case it replaces all occurrences of "%L" in the string with vbCrLf (which incidentally can also be written as vbNewLine).

Anyway, nice work.
Jan 18 '12 #6
cwebb
4 New Member
Those are some really slick tricks. They will speed my project up quite a bit. Thanks alot!
Jan 19 '12 #7
NeoPa
32,556 Recognized Expert Moderator MVP
A pleasure of course. Even more so as they're appreciated as intended :-)
Jan 19 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Twist Around | last post by:
We have to use a zebra printer to print some specialty labels. I was wondering if anyone had used python to output text to these. I know they use the Zebra Printing Language and before we got into...
6
by: dzemo | last post by:
I have mentioned printer but how to print on him from code? I tried like POS printer copy .txt to LPT port but don't work. I tried print test page- still nothing. Any ideas? thx --...
3
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this...
6
by: VJ | last post by:
I am able to print to File, which I am doing fine in our Program now. I want to be able to take this file and Print to a printer. Vijay
2
by: Beginner | last post by:
I have to print a Fedex shipping label on a Zebra(thermal) printer. I initially had the label information in a base64 string which I decoded into a memory stream. Now I need to send this memory...
13
by: ATJaguarX | last post by:
I have a Zebra S500 and multiple S600 label printers. http://www.zebra.com/id/zebra/na/en/index/products/printers/industrial_commercial/s600.html They are currently being used in our legacy...
1
by: steve | last post by:
Hi All Has anybody had experience with printing text and barcodes to Zebra label printers in VB.net 2005 Regards Steve
2
by: cchen1682005 | last post by:
Hi, I am writing an application in C#. Which can adjust the printing position of a Zebra printer, 110XiIII through program instesd of setting on Zebra's panel. Any help on this would be greatly...
0
by: bernardolira | last post by:
Hi all. I made a VB6 program to manage articles using barcodes, and got stuck trying to print barcodes. My printer is a Zebra TLP 2742 (Eltron 2844Z I guess). If I try to print using the EPL...
0
by: Raymond | last post by:
Hi All, Has any one work with FedEx Webservice with ASP? I am using ASP via SOAP to talk to FedEx Webservice, I have no problem printing the FedEx label with PNG or PDF, my problem is to print...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.