Problem printing labels

I have a C# WinForms app and am trying to print labels from it.  I need to
print a label each time a certain type of record is added, so I need to print
labels one at a time.  I set up a Word application and it worked fine for other
purposes, but when I added this code I get the error:

"method or property is not available because a document window is not active"

Here is the code:
bool SingleLabel = true;
object Name = "4013";
object Address = ClName.Text +"\r\nTest Company Name\tTest Rep";

oWord.Application.MailingLabel.DefaultPrintBarCode = false;

//First I tried this line

oWord.Application.MailingLabel.CreateNewDocument(ref Name,ref Address,ref missing,ref missing,ref missing);

//Then I tried this line

oWord.Application.MailingLabel.PrintOut(ref Name,ref Address,ref missing,ref missing,ref SingleLabel, ref missing,ref missing);

I saw similar code in numerous examples and do not know what is missing.  In one place there was a suggestion that it could be a MS bug and to be sure I had Office SP3, but I upgraded it only to get same results.  Word version is 9.0.6926 SP-3.

Any help is appreciated.  I did not think this would be difficult but now it is threatening my deadline!!!!!!!!!!!!!!!!!!!

Who is Participating?
moduloConnect With a Mentor Commented:
PAQed with points refunded (500)

Community Support Moderator
zoseriAuthor Commented:
FIgured it out for myself - but thought I would post the answer in case anyone else runs into this problem....

oWord.Application.Documents.Add(ref missing, ref missing,
      ref missing, ref missing);

Have to add this before trying to print the label.  This has the effect of "new blank document".  I thought that CreateNewDocument would do this for me, but apparently not!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.