Link to home
Start Free TrialLog in
Avatar of zoseri
zoseri

asked on

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!!!!!!!!!!!!!!!!!!!

Thanks
zoseri
Avatar of zoseri
zoseri

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial