Open Cash Drawer using VB for Access 2007, and USB Printer

Posted on 2009-04-06
Last Modified: 2013-11-28
I have designed a POS system in Access 2007 that uses a USB Epson TM-T88IV receipt printer, and a APG Vasario cash drawer. I can get the drawer to open when using the open cash drawer setting contained in the advanced drivers for the printer so I know the hardware works, but I need to open the drawer via VB for Access 2007 and thus far have been unable to do so.

I have tried the following two approaches unsuccessfully &

ESC Codes ...

Public Function OpenCashDrawer()
    Open "ESDPRT001" For Output As #1 'This is the Correct USB port for the Epson printer
    Print #1, Chr$(27) + Chr$(112) + Chr$(0) + Chr$(25) + Chr$(250)
    Close #1
End Function

This code does not produce an error, but does not open the drawer. I know the code fails relative to issues with using the USB port for for output, but I have been unable to open the USB port successfully.

This method does open the drawer successfully with printer pooling enabled and using port "LPT1" instead, but unfortunately the report itself won't print to the printer with pooling enabled (nothing is actually connected to LPT1), so that option does not solve the problem.

Using the Epson "control" font ...

Public Function OpenCashDrawer()
    Dim prnPrinter As Printer
    Dim sDeviceName As String
    sDeviceName = "EPSON TM-T88IV Receipt"
    For Each prnPrinter In Printers
      Debug.Print Printer.DeviceName
      If prnPrinter.DeviceName = sDeviceName Then
        msgbox "Printer: " & prnPrinter.DeviceName
        Set Printer = prnPrinter
        Printer.FontSize = 10
        Printer.FontName = "control" 'Epson printer control font
        Printer.Print "A" 'Open the cash drawer.
        Exit For
      End If
End Function

This code results in a "Method or Data Member Not Found" error message for both FontSize and FontName. I understand this code works great in VB, but does not work in VB for Access. I have also tried to use this code modified to change the font name and size on a form instead of the printer and get the same error message.

Anyone have a solution to successfully opening a USB port for output of printer codes, or to resolving the fontname and fontsize error within Access VB? Either answer would  solve this. Thanks!
Question by:BillMoody
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
  • 5
  • 5
  • 2
  • +2
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24083434

Have you tried contacting the makers of the Cash Drawer, directly?
    APG Vasario

If anyone would know how to do this, it would be them.


Author Comment

ID: 24083736
Thanks Jeff. Yes. I sent APG technical support an email this morning, and one to Epson as well. Hoping for a response soon. You wouldn't think opening a cash drawer through USB would be so difficult, but this has been a frustrating one.
The version of VB I am using is 6.5 BTW.
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24092745
I am sure it will turn out to be something simple
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.


Author Comment

ID: 24103683
Anyone have any suggestions for sending printer output to a USB port via VB?
LVL 57
ID: 24118442
Public Function OpenCashDrawer()
    Open "ESDPRT001" For Output As #1 'This is the Correct USB port for the Epson printer
    Print #1, CHR$(&H1B); CHR$(&H70); CHR$(&H0); CHR$(60); CHR$(120);
    Close #1
End Function
 I pulled that sequence right out of the Epson manual.
LVL 57
ID: 24118488
Scratch that last comment.  I just found the actual syntax for the command and it is variable (See screen shot).

LVL 57
ID: 24118690
you may want to try that anyway.  A longer/shorter pulse may be part of the problem with the USB port.
LVL 13

Expert Comment

by:John Mc Hale
ID: 24124940
I have come across USB printing problems on numerous occasions, particularly with Vista.

I have seen solutions where the USB printer is shared out, and then re-routed to LPT1:


Assuming the Epson printer is shared as epson

NET USE LPT1: \\localhost\epson

Maybe this may be worth a try?

LVL 57
ID: 24129500
Always amazes me with Windows that even on the simplest of stuff how much it still has to go back to it's DOS roots in order to get something to function correctly.
  I use another language called NPL and in many cases, I find that I have to map something to a LTP port to get printing to function correctly.

Author Comment

ID: 24138601
It pops when printer pooling is enabled and the printer is also assigned to LPT1 (in addition to its original USB port) so I know the code is right Same code as supplied above), at least for output to LPT1, but it does not open the drawer when I remove the pooling.  Does there need to be an adjustment to the code for USB?
This software package is done save this cash drawer issue. I am just about to install my beta location, and need to get this resolved, so your continued sassistance is appreciated so much.
LVL 57

Accepted Solution

Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 24138958
I just hunted around a bit and found this on EE, which has some VB 6.0 code which looks like it talkes more directly to the printer:
chekcout the code in the second comment.
Don't know if it will help or not.

Author Comment

ID: 24198312
Thanks for all of your help on this, but thus far, nothing has worked. I feel the code I am using is correct, at least for LPT1 ports, as it opens the drawer just fine with printer pooling enabled and assigning the printer to both the USB and LPT1 ports (but still connected only to the USB port), But when I remove sharing, and just try to open the drawer via the USB port only, nothing.
Is there something specific to using just the USB port that I am unaware of? This failure isn't making sense, given the code works when pooled.

Author Closing Comment

ID: 31567185
This ultimately workd. I had to do some tweeking to asing the default printer for the code to work, but it did! Thanks for the help. Would like to award you the points.

Expert Comment

ID: 37636999
Still curious how to let this work? I have a working solution. Look at the following code:

create a module with the following vb:

Option Compare Database
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Private Type DOCINFO
    pDocName As String
    pOutputFile As String
    pDatatype As String
End Type
Public Sub openTillDrawerUsb(ByVal sUsbPrinterName As String, ByVal sOpenCodes As String)

    Dim lPrinterHandle As Long
    Dim lpcWritten As Long
    Dim lRet As Long
    Dim sWriteData As String
    Dim MyDocInfo As DOCINFO
    Dim sCodeArray() As String
    Dim i As Integer
    On Error GoTo errError1

    If OpenPrinter(sUsbPrinterName, lPrinterHandle, 0) = 0 Then
        Err.Raise 1, , "USB Printer Name specified [" & sUsbPrinterName & _
            "] " & "when trying to open the till drawer wasn't valid"
    End If
    On Error GoTo errError2
    With MyDocInfo
        .pDocName = "DRAWERKICK"
        .pOutputFile = vbNullString
        .pDatatype = vbNullString
    End With
    lRet = StartDocPrinter(lPrinterHandle, 1, MyDocInfo)
    Call StartPagePrinter(lPrinterHandle)

    ' Split cash drawer code list into array
    sCodeArray = Split(sOpenCodes, ",")

    ' Convert array into actual characters to send to printer
    For i = 0 To UBound(sCodeArray)
        sWriteData = sWriteData & Chr$(Val(sCodeArray(i)))

    lRet = WritePrinter(lPrinterHandle, ByVal sWriteData, Len(sWriteData), lpcWritten)
    lRet = EndPagePrinter(lPrinterHandle)
    lRet = EndDocPrinter(lPrinterHandle)
    lRet = ClosePrinter(lPrinterHandle)
    On Error GoTo errError1
    Exit Sub
    lRet = ClosePrinter(lPrinterHandle)
    Err.Raise Err.Number, , Err.Description
End Sub
Sub KickDrawer()

Dim sPrinter As String
Dim sCodes As String

    ' Replace the name of your printer here if you are not
    ' using the default printer
    sPrinter = Printer.DeviceName
    ' This is for EPSON Tm-T88V receipt printer.  Replace here
    ' with a comma separated list of the codes required for
    ' your receipt printer
    sCodes = "27,112,48,55,121"
    Call openTillDrawerUsb(sPrinter, sCodes)
End Sub

After this call Kickdrawer from your vb and the drawer will kick

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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