By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,645 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Printing to Zebra LP2824

P: 4
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 :-)

Share this Question
Share on Google+
7 Replies


NeoPa
Expert Mod 15k+
P: 31,494
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

P: 4
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
Expert Mod 15k+
P: 31,494
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

P: 4
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
Expert Mod 15k+
P: 31,494
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

P: 4
Those are some really slick tricks. They will speed my project up quite a bit. Thanks alot!
Jan 19 '12 #7

NeoPa
Expert Mod 15k+
P: 31,494
A pleasure of course. Even more so as they're appreciated as intended :-)
Jan 19 '12 #8

Post your reply

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