Solved

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

Posted on 2014-04-24
6
929 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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 …

747 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

13 Experts available now in Live!

Get 1:1 Help Now