Sorry about the wait. What kind of printer do you have?
I'm going to take a shot in the dark here. This is just a basic coding for cash drawers in MS Access.
Dim intCOM1 As Integer Dim strCommandCodes As String
strCommandCodes = Chr$(16) & Chr$(20) & Chr$(1) & Chr$(0) & Chr$(2) ' using connector pin 2' strCommandCodes = Chr$(16) & Chr$(20) & Chr$(1) & Chr$(1) & Chr$(2) ' using connector pin 5intCOM1 = FreeFile
Open "Lpt1" For Binary As #intCOM1 'COM1 Put #intCOM1, , strCommandCodes Close intCOM1
If you are printing using a DOS program, make sure you use this as well.
net use lptx: \\printserver\sharename /persistent:yes
Please respond and let us know if you were able to code this correctly.
OK. Give me just a moment.
What version of Access are you using?
Thank you. Give me a moment. Come heck or high water, I'm gonna find an answer that will work.
Have you tried the codes that you provided already?
Ok. I'm here. Just let me know.
Ok. Was the first number 27 or 7?
This is the set of codes that I have. 27,112,48,55,121
At the moment, I don't have the access to do that. I do know that you have the correct codes and are doing everything correctly. I believe perhaps maybe there is a driver issue or maybe the cable just needs to be reseated.
OK. Let me check it out.
Is this a USB connection?
The coding looks right actually. I'm trying to find out what would be causing the error when you kick the drawer but not when you print a receipt.
Since you are using USB the LPT1 port won't kick the drawer. Let me see if I can come up with a sub to deter that.
You had it right before from what I am seeing. It's an issue with the USB, I'm 99 percent certain.
Can you issue the command in VB at all?
If you can issue this code in VB6, it will work. It bypasses the USB issue somehow.
sWrittenData = Chr(&H1B) & Chr(&H70) & Chr(0) & Chr(25) & Chr(30)
Also where it says "End Sub" replace it with "End Function".
Keep your original code. But try this. This is just a shot in the dark here.
Option ExplicitPrivate Type DOCINFO pDocName As String pOutputFile As String pDatatype As StringEnd TypePrivate Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As LongPrivate Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As LongPrivate Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As LongPrivate Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As LongPrivate Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As LongPrivate Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As LongPrivate Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As LongPublic Function OpenCashDrawer() 'Declare Vars Dim lhPrinter As Long Dim lReturn As Long Dim lpcWritten As Long Dim lDoc As Long Dim sWrittenData As String Dim MyDocInfo As DOCINFO ' 'Open connection with rpinter lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0) If lReturn = 0 Then MsgBox "The Printer Name you typed wasn't recognized." Exit Sub End If 'Set information MyDocInfo.pDocName = "OPENCASH" MyDocInfo.pOutputFile = vbNullString MyDocInfo.pDatatype = vbNullString ' 'Initiate the document lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo) Call StartPagePrinter(lhPrinter) ' 'Here is your line of code: sWrittenData = Chr(&H1B) & Chr(&H70) & Chr(0) & Chr(25) & Chr(30) ' 'Write to the printer lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten) ' 'Close printer connection lReturn = EndPagePrinter(lhPrinter) lReturn = EndDocPrinter(lhPrinter) lReturn = ClosePrinter(lhPrinter)End FunctionPrivate Sub Command1_Click() 'Open the cash drawer when this button is clicked OpenCashDrawerEnd Sub
In Access where you have your old code. Just try it and see if it works.
This code talks more directly to the printer.
Yes. Just make sure you save your original coding in case this doesn't work.
I have done all that I know to do. I would say your best bet would be to contact Epson themselves and see if they have better options. Your coding is good, though.
I can opt-out and see if someone else has any better ideas but if I were in your shoes, I'd call the people that made the printer.
If you were able to get a satisfactory answer to your question, please remember to rate the answer so that the expert can receive credit, as this is their livelihood. Thank you for using Just Answers and have a great day!
I appreciate the thought! I am actually headed out of town at the moment and was checking my messages really quick.
We have many talented Experts here who will be glad to assist you. I will be back on Monday if you'd like to speak with me. I will opt out but if you want to wait, just let us know and I'll help you on Monday.