I am using MS Access 2019
I want to empty the print queue (Using VBA) for a specific printer...if this cannot be done just empty all print jobs on all printers.
I am creating a POS using Access 2019. At one point the program ask if customer wants a receipt. IF the answer is NO I want to empty the receipt from the queue. What is happening now is I will get 100 customers who say NO, the 101th says yes and the entire print queue prints 101 receipts (all the past "NO")
The Computer: Windows 10 and 11
Printer: STAR TSP700II receipt printer (printer designated on receipt report)
I have tried this code but get an error:
Dim qd As Object
Set qd = CreateObject("Shell.Application").NameSpace(16)
qd.ParseName("EPSON WF-2650 Series").InvokeVerb ("Empty")
ERROR: Object variable or With block variable not set
Actual printer name from printer properties: "EPSON WF-2650 Series" which is 21 characters I call this code from a msgbox answer..........Call EmptyPrintQueue
CodePudding user response:
This code cancels all print jobs from all printers:
Public Sub OhSht()
Dim o As Object, ret
For Each o In GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2").ExecQuery("Select * from Win32_Printer")
ret = o.CancelAllJobs
Debug.Print o.Name, ret
Next
End Sub