Solved

Access VBA to print to a ZPL printer

Posted on 2014-04-16
12
1,650 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
  • 6
  • 3
  • 3
12 Comments
 
LVL 49

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 49

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 49

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 49

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 49

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 49

Expert Comment

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

/gustav
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

830 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