Solved

Access VBA to print to a ZPL printer

Posted on 2014-04-16
12
1,737 Views
Last Modified: 2014-04-25
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
Comment
Question by:schmir1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
12 Comments
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40006165
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
 
LVL 57
ID: 40006189
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
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40006220
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 57
ID: 40006239
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
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40006346
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
 
LVL 57
ID: 40006362
<<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
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40006452
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
 

Author Comment

by:schmir1
ID: 40007422
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
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40007951
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
 

Author Comment

by:schmir1
ID: 40021517
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
 

Author Closing Comment

by:schmir1
ID: 40021519
Thanks.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40021985
Great. Thanks for the feedback.

/gustav
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question