Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change 'Document Name' property for a print job

Status
Not open for further replies.

jab3

IS-IT--Management
Joined
Dec 23, 2003
Messages
2
Location
GB
Hi there

I need to change the 'Document name' property of a job sent to a printer queue - I'm working in Windows 2000 using VB6 sp5.

In particular, I'd like to change the 'Document Name' property of a job submitted from a Ms Word object using the 'PrintOut' method of the Ms Word App object v. 9.0.

The print job is to be processed by an application (OCE Prisma Satellite) that MUST identify the job by its 'Document name' property. If the job doesn't have EXACTLY the required name the process fails. Ms Word prefixes every print job with the string 'Microsoft Word - ', thus screwing the whole thing up.

This external application will process the print job directly from the printing queue once this job has been submiited. Therefore, nothing else has to be done apart from submitting the print job with the correct name.

To sum up, all I need to do is to merge a MS Word template with a merge file and then send the merged document(s) to a printer setting the required 'Document name' property for the print job.

Please, help.
 
This sample shows a sample printer selection form. It assumes you have added a combo box called cmbPrinters and a command button called cmdPrint and a textbox called txtDocName (which contains the name of the document you are printing).

Dim ptr As cPrinters

Private Sub cmbPrinter_Click()
ptr.SetPrinterByName cmbPrinter.Text
End Sub

Private Sub cmdPrint_Click()
If ptr.IsPrinterReady Then
ptr.DocumentName = txtDocName.Text
ptr.StartJob
On Error GoTo Handler
Printer.Print "test printout1."
' print more stuff here.
ptr.EndJob
MsgBox "Print job has completed."
Else
MsgBox "Could not print to " & cmbPrinter.Text
End If
Exit Sub

Handler:
MsgBox "An error occurred while trying to print the document. The document will be removed from the print queue."
ptr.EndJob
End Sub

Private Sub Form_Load()
Set ptr = New cPrinters
ptr.LoadPrinterCombo cmbPrinter
End Sub

 
Thanks very much Bubbler. Your text is perfectly correct when you print directly from VB using the 'Print' methid.

I was trying to rename a print job submitted by a Word Object using the 'PrinOut' method.

You'll find the solution I just come out with today in:


Thanks very much for your help again.

Merry X-mas.
 
Option Explicit
'\\ API declarations
Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long
DesiredAccess As Long
End Type

Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long

Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Private mhPrinter As Long

Private Type JOB_INFO_1
JobId As Long
lpPrinterName As String
lpMachinename As String
lpUserName As String
lpDocumentName As String
lpDataType As String
lpStatus As String
Status As PrintJobStatuses
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type

Private Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" _
(ByVal hPrinter As Long, _
ByVal JobId As Long, _
ByVal Level As Long, _
buffer As Long, _
ByVal pbSize As Long, _
pbSizeNeeded As Long) As Long

Private Declare Function SetJob Lib "winspool.drv" Alias _
"SetJobA" (ByVal hPrinter As Long, _
ByVal JobId As Long, _
ByVal Level As Long, _
pJob As Long, _
ByVal Command As Long) As Long

'\\ When changing information other than the position for JOB_INFO_1 and
'\\ JOB_INFO_2 you must set the Position member to JOB_POSITION_UNSPECIFIED
Private Const JOB_POSITION_UNSPECIFIED = 0

Private mJOB_INFO_1 As JOB_INFO_1
Private buffer() As Long

Private Sub RefreshJobInfo()

Dim lret As Long
Dim SizeNeeded As Long

ReDim Preserve buffer(0 To 1) As Long
lret = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer), SizeNeeded)

If SizeNeeded > 0 Then
ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
lret = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer) * 4, SizeNeeded)

With mJOB_INFO_1
.JobId = buffer(0)
.lpPrinterName = StringFromPointer(buffer(1), 1024)
.lpMachinename = StringFromPointer(buffer(2), 1024)
.lpUserName = StringFromPointer(buffer(3), 1024)
.lpDocumentName = StringFromPointer(buffer(4), 1024)
.lpDataType = StringFromPointer(buffer(5), 1024)
.lpStatus = StringFromPointer(buffer(6), 1024)
.Status = buffer(7)
.Priority = buffer(8)
.Position = buffer(9)
.TotalPages = buffer(10)
.PagesPrinted = buffer(11)
'Submitted is also here...
With .Submitted
.wYear = LoWord(buffer(12))
.wMonth = HiWord(buffer(12))
.wDayOfWeek = LoWord(buffer(13))
.wDay = HiWord(buffer(13))
.wHour = LoWord(buffer(14))
.wMinute = HiWord(buffer(14))
.wSecond = LoWord(buffer(15))
.wMilliseconds = HiWord(buffer(15))
End With
End With
End If
End Sub

Private Sub SavePrintJobInfo()

Dim lret As Long

With mJOB_INFO_1
buffer(0) = .JobId '\\ This cannot change and is ignored
buffer(1) = LPCSTR(.lpPrinterName) '\\ This is ignored and cannot be changed
buffer(2) = LPCSTR(.lpMachinename) '\\ also ignored
buffer(3) = LPCSTR(.lpUserName)
buffer(4) = LPCSTR(.lpDocumentName)
buffer(5) = LPCSTR(.lpDataType)
buffer(6) = LPCSTR(.lpStatus)
buffer(7) = .Status
buffer(8) = .Priority
buffer(9) = .Position
buffer(10) = .TotalPages
buffer(11) = .PagesPrinted
With .Submitted '\\ Also ignored
buffer(12) = MakeLong(.wYear, .wMonth)
buffer(13) = MakeLong(.wDayOfWeek, .wDay)
buffer(14) = MakeLong(.wHour, .wMinute)
buffer(15) = MakeLong(.wSecond, .wMilliseconds)
End With
End With

lret = SetJob(mhPrinter, mJobId, Level, buffer(0), 0)

End Sub

Public Sub ChangeDocName(byval JobId As Long, ByVal NewName As String)

pDef.DesiredAccess = PRINTER_ALL_ACCESS
lret = OpenPrinter(newname, mhPrinter, pDef)

If mhPrinter Then
Call RefreshJobInfo
mJOB_INFO_1.lpDocumentName = Newname
Call SaveJobInfo

Call ClosePrinter(mhPrinter)
End If

End Sub
 
Just posted the above code in case the link goes dead and users here are looking for the solution.


The above code was from Merrion at vbforums.com
(Forgot to give credit)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top