Newsgroup: it.comp.appl.access
Titolo: Report per stampante scontrini ?

Per pilotare le stampanti scontrini, tipo le Custom KubeII
 
https://www.custom.biz/en_GB/product/hardware/printers/pos-printers/kube-ii
 
 
https://docplayer.it/11440320-Pos-manuale-utente-kubeii-f-domc-0017i-manuale-comandi.html
 
 
solitamente si usa creare un file di testo coi comandi+dati e poi 
inviarlo alla stampante con vari metodi, il piu' semplice dei quali e' 
il comando 'copy' da sistema operativo
Mi chiedevo se qualcuno di voi sappia come ottenere lo stesso risultato 
usando i report standard di Access
La domanda quindi e':  e' possibile creare un report Access, con dati 
collegati a campi su tabelle del db 8quantita, codice articolo, prezzo, 
ecc..), che invii alla stampante solamente i caratteri costituenti i 
comandi 'recepiti' dalla stampante?
Tanto per capirci, un report di questo tipo dovra' spedire alla 
stampante una sequenza del tipo:
 
30021082 x 3,50
310110107portata000001050
3003
300408contante000000000
3010115Pezzi venduti 2
3011
3013
 
 
 

inserisci in un modulo
 
 
'---------
Option Compare Database
Option Explicit
 
 
'Declare PtrSafe Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As String, ByVal Level As Long, pPrinterEnum As Byte, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
 
Const PRINTER_ENUM_DEFAULT = &H1
 
'Type PRINTER_DEFAULTS
'        pDatatype As String
'        pDevMode As DEVMODE
'        DesiredAccess As Long
'End Type
 
'Private Declare PtrSafe Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrn As Long, pDefault As Any) As Long
Declare PtrSafe Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As LongPtr, pDefault As Any) As Long
 
 
'Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrn As Long, ByVal Level As Long, pDocInfo As DOC_INFO_1) As Long
Declare PtrSafe Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As LongPtr, ByVal Level As Long, pDocInfo As DOC_INFO_1) As Long
 
 
'Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Declare PtrSafe Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As LongPtr) As Long
 
 
'Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrn As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Declare PtrSafe Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As LongPtr, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
 
 
'Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Declare PtrSafe Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As LongPtr) As Long
 
'Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Declare PtrSafe Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As LongPtr) As Long
 
'Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Declare PtrSafe Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As LongPtr) As Long
 
'
Private Type DOC_INFO_1
    pDocName As String
    pOutputFile As String
    pDatatype As String
End Type
 
 
Public Sub SpoolFile(sFile As String, PrnName As String, Optional AppName As String = "Magazzino")
 
    Dim hPrn As Long
    Dim buffer() As Byte
    Dim hFile As Integer
    Dim Written As Long
    Dim di As DOC_INFO_1
    Dim i As Long
    Const BufSize As Long = &H4000
    '
    ' Extract filename from passed spec, and build job name.
    ' Fill remainder of DOC_INFO_1 structure.
    '
    If InStrRev(sFile, "\") Then
 
        '        For i = Len(sFile) To 1 Step -1
        '            If mid$(sFile, i, 1) = "\" Then Exit For
        '            di.pDocName = mid$(sFile, i, 1) & di.pDocName
        '        Next i
 
        di.pDocName = Mid$(sFile, InStrRev(sFile, "\") + 1)
 
    Else
        di.pDocName = sFile
    End If
    If Len(AppName) Then
        di.pDocName = AppName & ": " & di.pDocName
    End If
    di.pOutputFile = vbNullString
    di.pDatatype = "RAW"
    '
    ' Open printer for output to obtain handle.
    ' Set it up to begin recieving raw data.
    '
    Call OpenPrinter(PrnName, hPrn, ByVal 0&)
    Call StartDocPrinter(hPrn, 1, di)
    Call StartPagePrinter(hPrn)
    '
    ' Open file and pump it to the printer.
    '
    hFile = FreeFile
    Open sFile For Binary Access Read As hFile
    '
    ' Read in 16K buffers and spool.
    '
    ReDim buffer(1 To BufSize) As Byte
    For i = 1 To LOF(hFile) \ BufSize
        Get #hFile, , buffer
        Call WritePrinter(hPrn, buffer(1), BufSize, Written)
    Next i
    '
    ' Get last chunk of file if it doesn't
    ' fit evenly into a 16K buffer.
    '
    If LOF(hFile) Mod BufSize Then
        ReDim buffer(1 To (LOF(hFile) Mod BufSize)) As Byte
        Get #hFile, , buffer
        Call WritePrinter(hPrn, buffer(1), UBound(buffer), Written)
    End If
    Close #hFile
    '
    ' Shut down spooling process.
    '
    Call EndPagePrinter(hPrn)
    Call EndDocPrinter(hPrn)
    Call ClosePrinter(hPrn)
 
     Kill sFile
 
End Sub
 
'------------
 
 
per stampare  :
 
 
         dim io as integer
         io=freefile
 
         open "preconto.txt"  for output as io
 
         print #io, "comandi stampa1"
         print #io, "comandi stampa2"
 
         close #io
 
        Call SpoolFile( "preconto.txt", nomestampate)
 
 
 


!!! Urca !!!!
Sembra proprio lei
Mi fiondo a provarla
Ti ringrazio davvero molto