Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-06
15
Medium Priority
?
6,103 Views
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
     Next
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!
0
Comment
Question by:BillMoody
  • 5
  • 5
  • 2
  • +2
14 Comments
 
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.

JeffCoachman
0
 

Author Comment

by:BillMoody
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.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24092745
I am sure it will turn out to be something simple
;-)
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:BillMoody
ID: 24103683
Anyone have any suggestions for sending printer output to a USB port via VB?
0
 
LVL 58
ID: 24118442
Try:
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.
JimD.
0
 
LVL 58
ID: 24118488
Scratch that last comment.  I just found the actual syntax for the command and it is variable (See screen shot).
JimD.
 

Region-Capture.jpg
0
 
LVL 58
ID: 24118690
you may want to try that anyway.  A longer/shorter pulse may be part of the problem with the USB port.
JimD.
0
 
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:

e.g.

Assuming the Epson printer is shared as epson

NET USE LPT1: \\localhost\epson

Maybe this may be worth a try?

0
 
LVL 58
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.
JimD.
0
 

Author Comment

by:BillMoody
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.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 750 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:
http://www.experts-exchange.com/Apple/Software/Filemaker_Pro/Q_24067409.html
chekcout the code in the second comment.
Don't know if it will help or not.
JimD.
0
 

Author Comment

by:BillMoody
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.
Bill
 
0
 

Author Closing Comment

by:BillMoody
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.
0
 

Expert Comment

by:Assist_Automatisering
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)))
    Next

    lRet = WritePrinter(lPrinterHandle, ByVal sWriteData, Len(sWriteData), lpcWritten)
       
    lRet = EndPagePrinter(lPrinterHandle)
    lRet = EndDocPrinter(lPrinterHandle)
   
    lRet = ClosePrinter(lPrinterHandle)
    On Error GoTo errError1
   
    Exit Sub
   
errError2:
    lRet = ClosePrinter(lPrinterHandle)
errError1:
    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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

782 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