Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access VBA to print to a ZPL printer

Posted on 2014-04-16
12
Medium Priority
?
1,898 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 51

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 58
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 51

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 58
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 51

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 58
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 51

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 51

Accepted Solution

by:
Gustav Brock earned 1500 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 51

Expert Comment

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

/gustav
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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