Link to home
Start Free TrialLog in
Avatar of schmir1
schmir1Flag for United States of America

asked on

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
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

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
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.
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
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.
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
<<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.
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
Avatar of schmir1

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of schmir1

ASKER

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
Avatar of schmir1

ASKER

Thanks.
Great. Thanks for the feedback.

/gustav