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

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!
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor President / OwnerCommented:
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.
Jeffrey CoachmanMIS LiasonCommented:

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.

BillMoodyAuthor Commented:
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.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Jeffrey CoachmanMIS LiasonCommented:
I am sure it will turn out to be something simple
BillMoodyAuthor Commented:
Anyone have any suggestions for sending printer output to a USB port via VB?
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Scratch that last comment.  I just found the actual syntax for the command and it is variable (See screen shot).

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
you may want to try that anyway.  A longer/shorter pulse may be part of the problem with the USB port.
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
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?

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
BillMoodyAuthor Commented:
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.
BillMoodyAuthor Commented:
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.
BillMoodyAuthor Commented:
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.
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.