Abort printing

R

RB Smissaert

Is there any way in VB to abort a print job that is in progress?
I am talking here about the situation where paper is coming out of the
printer.
I had a good search for this, but nil found sofar.
Thanks for any advice.

RBS
 
K

Karl E. Peterson

RB said:
Is there any way in VB to abort a print job that is in progress?
I am talking here about the situation where paper is coming out of the
printer.

Usually, by that point, the entire job has traversed the wire to the printer, and is
beyond Windows' control. Only thing I've found that works, by then, is yanking the
power cord.
 
R

RB Smissaert

But you can stop it via control panel (I think I did once), so why can't
this be done in VB?

RBS
 
K

Karl E. Peterson

RB said:
But you can stop it via control panel (I think I did once), so why
can't this be done in VB?

Well, yeah, you can always *try* to pull an Abort on it, sure. But as I said, if the
pages are already spitting, the odds are that most/all of the bits have already
spooled. To get an idea of how to send an Abort, see
http://vb.mvps.org/samples/PrnInfo -- in particular, the following methods of the
CPrinterJobs class:

Public Function ControlCancel(ByVal JobId As Long) As Boolean
Dim os As OSVERSIONINFO
' NT4 is the dividing line between two different
' control codes for this call.
os.dwOSVersionInfoSize = Len(os)
Call GetVersionEx(os)
' Attempt to cancel passed job.
If os.dwPlatformId = VER_PLATFORM_WIN32_NT And os.dwMajorVersion >= 4 Then
ControlCancel = SendControl(JobId, jcDelete)
Else
ControlCancel = SendControl(JobId, jcCancel)
End If
End Function

Private Function SendControl(ByVal JobId As Long, ByVal ControlCode As
JobControlCodes) As Boolean
Dim hPrn As Long
' Get handle to printer.
Call OpenPrinter(m_DevName, hPrn, ByVal 0&)
If hPrn Then
' Send requested control code.
SendControl = CBool(SetJob(hPrn, JobId, 0, ByVal 0&, ControlCode))
Call ClosePrinter(hPrn)
' Update all object data.
Call Me.Refresh
End If
End Function

That will, at least, stop Windows from sending any more bits down the wire. What's
already in the printer's internal buffer is out of reach, however.

Good luck... Karl
 
K

Karl E. Peterson

Hi Anne --

Hey, that'd be great! If you'd also like to display banner(s), take a look at
http://classicvb.org/#Banners (others are also available, if none of those work!)

Btw, we had some "server issues" with signatures last week. If you hear of anyone
that says they tried but were rejected, please urge them to take another shot at it.
I'm fairly certain the problem was resolved.

Thanks... Karl
 
M

MikeD

Even via Control Panel or the Printer dialog (double-clicking the print icon
in the systray, and these might even be one-in-the-same), you can only abort
what hasn't already been fed to the printer. If you're printing a large
document, it might be entirely spooled, but Windows is feeding it to the
printer in the background. At what point you can abort printing, if you can
at all, depends on the printer itself (i.e. how much memory it has).

As far as VB, it only lets you abort if you're still spooling (i.e., there's
been no Printer.EndDoc). You might be able to use the AbortPrinter Win32API
function to abort a print job that you've "completed" in VB (IOW, you've
executed Printer.EndDoc), but even then, only what *hasn't* been sent to the
printer already would get aborted. Also, this would depend on whether
spooling and background printing is enabled (and possibly even other printer
settings supported by any given printer).
 
A

Anne Troy

Okay, I've got one here: http://www.officearticles.com/
And I also have about 30,000 posts around the internet on forums, which will
all update when I change my signature. For any that let me, I'm going to put
the banner, tho I may be stuck using the vBulletin code and not the HTML. :)
Let's see what I can do.
*******************
~Anne Troy

www.OfficeArticles.com
 
R

RB Smissaert

OK, thanks, I can see that I need a different approach.
I n my particular case I am printing lots of small documents from Excel with
OLE automation to Word like this:

Dim wd As Word.Application
Set wd = New Word.Application

Go = 3

For i = 1 To UBound(arrFiles)
DoEvents
If Go = 1 Then
Exit For
End If
wd.Documents.Open FileName:=strPath & "\" & arrFiles(i),
ReadOnly:=True
wd.ActiveDocument.PrintOut Background:=False
wd.ActiveDocument.Close wdDoNotSaveChanges
ShowProgressMessage " " & _
Round(100 * (i / UBound(arrFiles)), 0) & _
" % done"
Next

What I need here is either a notification event from the printer that
another document is done and only then
go to the next element of the array of documents. Not sure this can be done.
Or the other way is just to ask the user: how many seconds do you want to
wait in between the documents?
The wait period may then have to be a loop with DoEvents to get the keyboard
press (spacebar) that sets the variable
Go to 1.
Any further suggestions?


RBS
 
K

Karl E. Peterson

RB said:
What I need here is either a notification event from the printer that
another document is done and only then
go to the next element of the array of documents. Not sure this can
be done.

You could monitor the printer for a "Ready" status.
 
R

RB Smissaert

Thanks, will try that.
I now have just asked the user how long printing one page roughly takes and
pause the loop for this time.
Monitoring the printer will be much slicker.

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top