Solved

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

Posted on 2014-04-24
6
965 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

773 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