Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why won't this print?

Posted on 2011-09-16
4
Medium Priority
?
373 Views
Last Modified: 2012-05-12
When the print button is clicked, a document is created, then it should print. I can see the document spooling in the printer queue, then printing.  I get the message 'This document has been sent to the printer', but nothing comes out of the printer.

I've been using this as a guide:

http://www.java2s.com/Tutorial/VB/0440__Windows/CreateWorddocumentandprint.htm

Should I be using another method?



Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim wdApp As New Word.Application
Dim wdDoc As New Word.Document

wdDoc = wdApp.Documents.Add
wdDoc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument
With wdDoc
   .Range.InsertAfter("Employer Information")
   .Range.Font.Name = "Arial"
   .Range.Font.Size = 14
   .Range.InsertParagraphAfter()
   .Range.InsertAfter("Employer: " & AcctNum.Text.ToString)
   .Range.Font.Name = "Arial"
   .Range.Font.Size = 12
   .Paragraphs.Item(1).Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter    
   .Paragraphs.Item(2).Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
   .Range.InsertAfter("Business Name: " & txtEmployerName.Text)
End With
Try
  wdDoc.PrintOut(True, True)
Catch ex As Exception
    Dim msg As String = String.Format("An error occured: {0}", ex.Message)
    MessageBox.Show(msg)
End Try
wdApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
wdApp.Quit()
wdApp = Nothing
End Sub

Open in new window

0
Comment
Question by:bgernon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 36550164
try setting the BackGround argument (of the Printout method) to False
0
 

Author Comment

by:bgernon
ID: 36550269
It worked.  
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1500 total points
ID: 36550278
wdDoc.PrintOut(True, True)

The second True. It tells Word to append to a file, so the printout is not sent to the printer. Try wdDoc.PrintOut(True)
0
 

Author Closing Comment

by:bgernon
ID: 36550308
I tried this just seconds before your response. It worked. Thanks.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question