[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1080
  • Last Modified:

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

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
schmir1
Asked:
schmir1
  • 3
  • 2
2 Solutions
 
IrogSintaCommented:
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
 
Helen FeddemaCommented:
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
 
schmir1Author Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
schmir1Author Commented:
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
 
IrogSintaCommented:
I'm glad you got it working.

:-)
Ron
0
 
schmir1Author Commented:
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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now