Solved

Using Access VBA to print to a special label printer on COM1

Posted on 2014-04-24
6
985 Views
Last Modified: 2014-05-05
I'm trying to send simple string data to our special label printer on COM1.  The printer is a Brady TLS PC Link printer if that helps.  It takes codes like <STX>F for form feed.  I've tried the following but the printer occassionally blinks a green light but nothing else.  Here is my sample code:
  strLbl = "<STX>L" & _
              "19000090000000012345<CR>" & _
              "<STX>G"
             
  Open "COM1:" For Output As #1
  Print #1, strLbl
  Close #1
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
  • 3
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 500 total points
ID: 40021720
I'm no expert with this printer but according to a couple of pages in the manual you need to send the ASCII value of the <STX> and <CR> control characters.  So try this:

strLbl = Chr(2) & "L" & _
              "19000090000000012345" & Chr(13) & _
              Chr(2) & "G"

Ron
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40026239
Here is some code to print to a special printer, then return to the default printer.  You will need to know the label printer's name as used in code; to get this, run the second procedure.

Public Sub PrintToSpecificPrinter(strPrinter As String, strReport As String)
'Created by Helen Feddema 12-Feb-2010
'Last modified by Helen Feddema 12-Feb-2010

On Error GoTo ErrorHandler

   Dim prtCurrent As Printer
   Dim prtDefault As Printer
   
   'Save current default printer
   Set prtDefault = Application.Printer
   Debug.Print "Current default printer: " & prtDefault.DeviceName
   
   'Select a specific printer as new default printer
   Application.Printer = Printers(strPrinter)
   
   'Print the report
   DoCmd.OpenReport strReport
   
   'Set printer back to former default printer
   Application.Printer = prtDefault
      
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & _
      Err.Description
   Resume ErrorHandlerExit

End Sub

Public Function ListPrinters()
'Lists Access printer names as used in VBA code
'to the Immediate window
  
   Dim prt As Access.Printer
   
   For Each prt In Application.Printers
      Debug.Print prt.DeviceName
   Next prt
   
End Function

Open in new window

0
 

Author Comment

by:schmir1
ID: 40030944
Thanks IrogSinta, that's got me on the right track.  Still can't get it to print but it does a FF.  Here is what I have (see anything obvious?):
'<STX>n ;put printer in inches mode - chr(2) & "n"
'<STX>L ;enter label format mode  - chr(2) & "L"
'490000803000030Sample<CR> ;specify text at X=0.30”,Y=3.00” - Sample & chr(13)
'X<CR> ;exit label format mode - "X" & chr(13)
'<STX>Q0002 ;set print quantity to 2 labels
'<STX>G ;print two identical labels
  strLbl = Chr(2) & "n" & Chr(2) & "L" & _
           "490000800300030Sample" & Chr(13) & "X" & Chr(13) & _
           Chr(2) & "G"
  Open "COM1:" For Output As #1
  Print #1, strLbl
  Close #1
0
Independent Software Vendors: 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!

 

Accepted Solution

by:
schmir1 earned 0 total points
ID: 40033480
Here is what worked:
  Open "COM1:" For Output As #1
  For i = 1 To intNumtoPrint
    strSN = "SN " & CStr(lngSN)
    strLbl = Chr(2) & "n" & Chr(2) & "L" & _
             "490000401900000" & strProjPartLabel & Chr(13) & _
             "490000401900010" & strSN & Chr(13) & _
             "E" & Chr(13)
    Print #1, strLbl
    lngSN = lngSN + 1
  Next
  Close #1
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40033808
I'm glad you got it working.

:-)
Ron
0
 

Author Closing Comment

by:schmir1
ID: 40041629
It works.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

733 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