Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1977
  • Last Modified:

Access VBA to print to a ZPL printer

I'm looking for some VBA to get me started in printing to a ZPL printer on lpt1.  Basically, I need to print:
  Part Number
  Lot #                 Pack #
  Home
  Description
0
schmir1
Asked:
schmir1
  • 6
  • 3
  • 3
1 Solution
 
Gustav BrockCIOCommented:
That should be quite easy:

        strPort = "LPT1:"
        Open strPort For Output As #1
            Print #1, "Part Number: " & strPartNumber
            Print #1, "Lot #: " & CStr(lngLot) & "    Pack #: " & CStr(lngPack) & ""
            Print #1, "Home: " & strHome
            Print #1, "Description: " & strDescription
        Close #1

/gustav
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
or even simpler; just write a report and print it to the printer.  Of course it's probably not that simple, as more then likely your looking to do some bar coding.

I would however stick with the report approach and buy a 3rd party library to do the bar coding.   Something like Abarcode.

Jim.
0
 
Gustav BrockCIOCommented:
For this type of printers it would in no way be simpler to write a report to write four lines of text.
Further, it is much slower. Nothing beats direct print as it prints instantly and, constantly, at the printer's maximum speed.

/gustav
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I was saying "simpler" in the overall context of printing.   I'm assuming this is just a start.  And what happens when bar codes are required?  when it's hooked to something other then LPT1 like a USB port?  Starting to handle all those details will make a VBA code approach far more complex then going the report route.  So more likely then not, they'll be far better off using a report.  

I've also found that for whatever reason, many assume that simply because it is a thermal printer, they assume that it must be handled in some special way (aka code) and a normal Access report cannot be used.  It can be and quite easily.

More likely then not, they'll be far better off using a report.  In fact I haven't seen VBA code used to drive printing since we basically gave up on dot matrix (their still around, but their getting pretty rare to find).

Jim.
0
 
Gustav BrockCIOCommented:
I can't tell, only the questioneer will know how complex this report may be.

Anyway, creating and testing a report for these printers is not a five-minute task, rather a five-hour task. I've written many reports for matrix and label printers, and it has often taken two to three times more than expected before the last tiny detail is settled.

/gustav
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<I can't tell, only the questioneer will know how complex this report may be.>>

 Quite true and what they posted may all it may be.   My gut hunch is not, but clearly I could be wrong.   Generally though when someone goes to a thermal printer, their looking to do bar coding, graphics, etc. and driving all that in code is rough (years ago, I used to do it that way - knew ZPL pretty well back then!).

<<Anyway, creating and testing a report for these printers is not a five-minute task, rather a five-hour task.>>

 Hasn't been my experience.  I do thermal bar code printing out of Access quite a bit and  I've found it to be pretty straight forward.  I always use Seagull Scientific Drivers.   Only thing you really need to watch out for is page size/margins.  

I doubt strongly that it would take me more then five minutes to do what was described if the drivers and printer were already in.

With the correct drivers, it's no different then printing to any other Windows based printer.

Jim.
0
 
Gustav BrockCIOCommented:
I have only worked with the Axiohm label printers. You had to drive them like a matrix printer using the built-in fonts and at fixed line spacing. If not, they switched to drawing mode where all chars are drawn by several passes, thus bringing the printing speed to an unacceptable low, not acceptable for POS use where you - literally - count every second in the process.

Of course, when you have managed to get your hand on it, it is not at all difficult but, again, I didn't feel that was the situation of the questioneer.

/gustav
0
 
schmir1Author Commented:
I tried this from gustav:
        strPort = "LPT1:"
        Open strPort For Output As #1
            Print #1, "Part Number: " & strPartNumber
            Print #1, "Lot #: " & CStr(lngLot) & "    Pack #: " & CStr(lngPack) & ""
            Print #1, "Home: " & strHome
            Print #1, "Description: " & strDescription
        Close #1

I get no output from the above.

I got the following from a web page and it prints "Test" 3 times but doesn't fit the 1" x 2" label paper.
      strData1 = "^XA^MCY^XZ" & _
    "^XA^LRN^FWN^CFD,24^LH0,0^CI0^PRA^POI^PMN" & _
    "^XZ^XA FT113" & _
    "^FO89,20^A0N,25,20 ^FDTest^1,1^FS" & _
    "^FO93,45^A0N,25,18^FTest1^1,1^FS" & _
    "^FO117,75^AB^FD" & Snum & "^1,1^FS" & _
    "^PQ3,0,1,Y^XZ"   Open "LPT1:" For Output As #1

    Print #1, strData1
    Close #1

It uses ZPL and I think I need to do that but need to modify it heavily to make it fit my needs described at the start.

Any ideas?
0
 
Gustav BrockCIOCommented:
Well, my code was just air code for a start. You should be able to figure out that the example parameters have to be replaced with those of yours, and control codes for font size etc. have to be applied.

You should start studying the printer manual and the control codes:

http://www.zebra.com/id/zebra/na/en/documentlibrary/manuals/en/zpl_ii_programming2.File.tmp/45541L-002_RA.pdf

/gustav
0
 
schmir1Author Commented:
Here is the what worked:

  strLbl = "^XA ^CFD,18,10" & _
             "^FO40,40 ^FD" & strComponent & "^FS" & _
             "^FO40,70 ^FD" & strLot & "^FS" & _
             "^FO290,70 ^FD" & strPack & "^FS" & _
             "^FO40,100 ^GB 370,2 ^FS" & _
             "^FO40,120 ^FD" & strHomeNQ & "^FS" & _
             "^FO40,150 ^FDDescription ^FS" & _
             "^FO40,180 ^ABN, 12,5 ^FD" & strDescNQ & "^FS" & _
            "^XZ"
             
  Open "LPT1:" For Output As #1
  Print #1, strLbl
  Close #1
0
 
schmir1Author Commented:
Thanks.
0
 
Gustav BrockCIOCommented:
Great. Thanks for the feedback.

/gustav
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now