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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Print job deleted" when using Document.PrintOut 1

Status
Not open for further replies.

JNeave

Programmer
Jan 28, 2002
125
GB
The Task: Insert A4 images into a word document and print them using OLE and VB. The code was created by recording macros and modifying the VBA code.

The print jobs go into the queue, but the server reports "Print job deleted" in it's event log. This does not happen if I use .SaveAs instead of PrintOut and manually print the document.

Mostly the print job is deleted, sometimes it prints out the first couple of inches of the page.

Any Clues?

THE CODE
------------
Code:
If oWordApp Is Nothing Then
  Set oWordApp = CreateObject("Word.Application")
End If
                                 
oWordApp.WindowState = 2 ' wdWindowStateMinimize
oWordApp.Visible = True
     
oWordApp.Documents.Add DocumentType:=0 'wdNewBlankDocument
     
Set oNewDoc = oWordApp.ActiveDocument
     
strFileName = oSI.fn_ScanImage_GetPath
            
Call gflFreeFileInformation(gflFileInfo)

eRet = gflGetFileInformation(strFileName, -1, gflFileInfo)

If eRet <> GFL_NO_ERROR Then
  Err.Raise vbObjectError + eRet, &quot;GFL SDK&quot;, extGetStr _
  (gflGetErrorString(eRet))
End If


With oNewDoc.PageSetup
  If gflFileInfo.Width > gflFileInfo.Height Then
    .orientation = 1 'wdOrientLandscape
  Else
    .orientation = 0 'wdOrientPortrait
  End If
    .TopMargin = 0 'oWordApp.CentimetersToPoints(3)
    .BottomMargin = 0 'oWordApp.CentimetersToPoints(3)
    .LeftMargin = 0 'oWordApp.CentimetersToPoints(3)
    .RightMargin = 0 'oWordApp.CentimetersToPoints(3)
  End With
     
oNewDoc.Shapes.AddPicture(strFileName, False, _
               True, , , , ,oWordApp.Selection.Range)_
               .WrapFormat.Type = 4 'wdWrapTopBottom

blnOK = oSI.fn_ScanImage_RecordsetMove(enMoveNext, True, _
oConn, strErrMsg)
     
     
Do Until oSI.fn_ScanImage_RecordsetEOF Or Not blnOK
                     
  strFileName = oSI.fn_ScanImage_GetPath
                
  Call gflFreeFileInformation(gflFileInfo)
    
  eRet = gflGetFileInformation(strFileName, -1, gflFileInfo)
    
  If eRet <> GFL_NO_ERROR Then
    Err.Raise vbObjectError + eRet, &quot;GFL SDK&quot;, extGetStr _
    (gflGetErrorString(eRet))
  End If
                     
  oWordApp.Selection.EndKey Unit:=6 'wdStory
  oWordApp.Selection.InsertBreak _
  Type:=2 'wdSectionBreakNextPage

  With oWordApp.Selection.PageSetup
    If gflFileInfo.Width > gflFileInfo.Height Then
      .orientation = 1 'wdOrientLandscape
    Else
      .orientation = 0 'wdOrientPortrait
    End If
    .TopMargin = 0
    .BottomMargin = 0
    .LeftMargin = 0
    .RightMargin = 0
    .SectionStart = 2 'wdSectionNewPage
  End With
                
  oNewDoc.Shapes.AddPicture(strFileName, False, _
                   True, , , , , oWordApp.Selection.Range) _
                   .WrapFormat.Type = 4 'wdWrapTopBottom 
                
  blnOK = oSI.fn_ScanImage_RecordsetMove(enMoveNext, _
              True, oConn, strErrMsg)
     
Loop
            
oNewDoc.PrintOut Range:=0, Item:= 0, Copies:=1, Pages:=&quot;&quot;, _
                 PageType:=0, ManualDuplexPrint:=False, _
                 Collate:=True, Background:=True, _
                 PrintToFile:= False, PrintZoomColumn:=0, _
                 PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
                 PrintZoomPaperHeight:=0
            
oNewDoc.Close False
            
Set oNewDoc = Nothing

oWordApp.Quit

Set oWordApp = Nothing
 
Its your oNewDoc.Close and oWordApp.Quit lines that are causing the problem. Try remming that section out. I had that problem - the code executes quicker than the print spooler so in effect it shuts off its instruction to the printer before its even got there.


Asjeff
 
Hi, yep, that did it.

Actually I changed it to Background:=False, forcing the code to stop and wait for the job to spool.

Cheers,

Jim.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top