Solved

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

Posted on 2014-04-24
6
955 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
Backup Your Microsoft Windows Server®

Backup 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.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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 …

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now