|
-
Aug 20th, 2003, 05:48 AM
#1
Thread Starter
Junior Member
[Resolved] Printing: Set Document Name in Print Queue (thanks Merrion)
Question 1
When I print from VB6 the local print queue (spooler, print manager or whatever its called) shows document name as "Microsoft Visual Basic"
Is there a simple way of changing that to a more meaningful document name - such as the client's account number etc? (by 'simple' I mean without all that terrifying API stuff that gives me the willies - If API is the only way could somebody please give me some very straightforward code as I am very very newbie when it comes to API.)
Question 2
Is there a simple (see definition above) way of getting back from the printer a value to say it has satisfactorily completed a particular print job. My printer loves to crash in the middle of a stack of documents "Your job waiting to be printed was deleted" and I have no idea which one of them failed to print without manually going through the whole stack and trying to remember which ones I had just tried to print.
I have searched the knowledge base and previous posts and nothing yet meets my needs (or my definition of simple!)
Thanks in anticipation...
Last edited by mdicoope; Aug 21st, 2003 at 08:07 AM.
-
Aug 20th, 2003, 06:12 AM
#2
It isn't simple - but if you're prepared to do some reading then there's a bunch of VB/Prining articles on my company site
-
Aug 20th, 2003, 07:03 AM
#3
Thread Starter
Junior Member
Thanks Merrion,
I have previously looked at your site and I confess I have much reading to do on the basics of API before I can get my head around that level of complexity.
I have downloaded your EventVB dll and help file. I am still puzzled as to how I go about renaming the Document Name in Print Queue. In the object browser, Document Name is a member of EventVB.ApiPrintJob but it is listed as read-only.
Sorry to be a pain but could you explain in words of one syllable or less if you can change the document name using EventVB and if so, how.
Thanks...
-
Aug 20th, 2003, 07:43 AM
#4
Things are left out of the EventVB.dll, either because they are not possible or because I lack the wit and will to implement them. Fortunately in this case it is the latter. I shall look into this after work...If I'm lucky it is just a case of modifying the ApiPrintJob code thus:-
VB Code:
Public Property Let DocumentName(ByVal newname As String)
Call RefreshJobInfo(1)
mJOB_INFO_1.lpDocumentName = newname
mJOB_INFO_1.Position = JOB_POSITION_UNSPECIFIED
Call SavePrintJobInfo(1)
End Property
-
Aug 20th, 2003, 02:47 PM
#5
Frenzied Member
EventVB_I.dll updated as per above - get it here
-
Aug 21st, 2003, 02:06 AM
#6
Thread Starter
Junior Member
Thanks for making the change Merrion. I really appreciate your help so far.
I have downloaded the new version and reset the project reference to the updated version and I find DocumentName is no longer a read-only property of ApiPrintJob - so far so good.
Now in my cmdPrint_Click event procedure, I have done this:
VB Code:
Dim prJob as New ApiPrintJob
printer.print 'etc. etc.
prJob.DocumentName = "A catchy name"
printer.enddoc
and i get Runtime error 6. The handle is invaild
and if I do Set prJob.DocumentName = "Something Stunning"
then I get Compile Error: Invalid Use of Property
I have tried setting the name both before and after the Printer.Enddoc method with the same result
Obviously I am missing something. Do I need to reference an object higher in a heirarchy than ApiPrintJob or is there something else I must do so that the handle is set to the appropriate printer/print job. Please indulge me a little further...
-
Aug 21st, 2003, 04:20 AM
#7
Before you can use any of the EventVB classes you need to instantiate the ApiFunctions class as this is used to communicate any API errors to your program etc.
VB Code:
Dim Withevents vbLink As ApiFunctions
'....
Private Sub Form_Load()
Set vbLink = New APIFunctions
End Sub
Then you need to access the Print Job from it's Printer's job queue.....
VB Code:
Public Sub RenameJob(ByVal OldName As String, ByVal NewName As String)
Dim vbPrinter As ApiPrinter
Dim vbJob As ApiPrintJob
Set vbPrinter = New ApiPrinter
vbPrinter .DeviceName = Printer.DeviceName
For Each vbJob In vbPrinter.PrintJobs
If vbJob.DocumentName = OldName Then
vbJob.DocumentName = NewName
End If
Next vbJob
End Sub
-
Aug 21st, 2003, 07:57 AM
#8
Thread Starter
Junior Member
Changing Document Name in Print Spooler [RESOLVED]
Sir Merrion, I salute you. It works. Thankyou.
I made a slight modification to your suggested code. Rather than call a subroutine that renames every job in the list, I want each job to have a unique name. Therefore I have used the following code immediately after my Printer.EndDoc method - I am assuming that jobs are added to the end of the queue - so that the most recent (ie current) job should be vbPrinter.PrintJobs.Count
VB Code:
Printer.EndDoc
Set vbJob = vbPrinter.PrintJobs(vbPrinter.PrintJobs.Count)
vbJob.DocumentName = "Account no " & frmClient.accountID
Again, a thousand thanks. May your road always be smooth etc.
-
Aug 21st, 2003, 08:32 AM
#9
In a really high use print queue it is possible that another job might be added between EndDoc and vbJob.DocumentName = "Account no " & frmClient.accountID but highly unlikely.
Note that unless you are logged in as an administrator you will not be able to change the document name on someone else's print job anway.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|