Custom form created in 2003 won't print since upgrade to 2007

L

Lori_CB

We created multiple Outlook forms that print to Word templates via code in a
Print button. The forms were created in 2003. We recently upgraded to 2007.
Now, when we click the button, the Word template prints but it doesn't
contain the information from the form.

Any ideas?
 
S

Sue Mosher [MVP]

Code in a print button on the form or in Word? You may want to add MsgBox
statements to the code to help you see how it's branching and executing.
 
L

Lori_CB

The code is for the Print button on the Outlook form. It's used to open
Word, populate the Word fields, print the document and close Word.
 
L

Lori_CB

I tried the msgbox and the fields are getting filled in properly.

When I try to use the Script Debugger, it says the feature is not available
and to run setup again. I'm waiting for a reply from our Help Desk.
 
S

Sue Mosher [MVP]

Script debugger is an optional component that may not have been installed;
it definitely won't work on Vista unless you also have Visual Studio. :(
That's why I suggested using MsgBox statements.

What do you mean by "the fields are getting filled in properly" -- the
fields in the Outlook item or the fields in the Word document? What happens
if you change the code so that the Word document displays instead of being
printed?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
L

Lori_CB

We have XP Professional, so I'm hoping to get it back. It's another thing
that stopped working after the upgrade. There must be something to tweak.

I did a message box for the Outlook field value and for the Word field
value. Both were correct.

I changed oDoc.PrintOut to oDoc.Display and got the following error message:
"Object doesn't support this property or method: 'oDoc.Display'"

Should I be changing something else too?

Thanks for all your help and patience.
 
S

Sue Mosher [MVP]

The object browser (F2 in VBA) is your friend. If you look at the Document
object in the Word library, you'll see that it has no Display method, but it
does have an Activate method and Window.Visible property.

You might want to show enough of your code so we can see how you're creating
the document and printing it. Please DO NOT show all the code for filling
the fields; as you said, it's clear that's working.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
L

Lori_CB

The code I've been referring to is in Outlook, not Word.

Here's what I'm doing when trying to display the Word document
(see <<< comments in the code):
Sub cmdPrint_Click()
Set oWordApp = CreateObject("Word.Application")
If oWordApp Is Nothing Then
MsgBox "Couldn't start Word."
Else
Dim oWordApp
Dim oWordDoc
Dim bolPrintBackground

' Open a new document
Set oDoc = oWordApp.Documents.Add
("\\w2kcbutler\data\eforms\pcrenewal2.dot")

' <<< deleted setting the field values

' Get the current Word setting for background printing
bolPrintBackground = oWordApp.Options.PrintBackground

' Turn background printing off
oWordApp.Options.PrintBackground = False

' Print the Word document
'oDoc.PrintOut <<< commented out
oDoc.Display <<< added

' Restore previous setting
oWordApp.Options.PrintBackground = bolPrintBackground

' Close and don't save changes to the document
'Const wdDoNotSaveChanges = 0 <<< commented out
'oDoc.Close wdDoNotSaveChanges <<< commented out

' Close the Word instance
'oWordApp.Quit <<< commented out

' Clean up
Set oDoc = Nothing
Set oWordApp = Nothing
End If
End Sub
 
S

Sue Mosher [MVP]

The code may be in Outlook, but you're using Word objects, so you need to
pay attention to what properties and methods those objects expose. Don't
assume you know what they are; look them up in the object browser.

Did you try using the Activate method I pointed out?
 
L

Lori_CB

I tried the Activate and PrintPreview methods. Each time, nothing happened
when I clicked the Outlook Print button.
 
S

Sue Mosher [MVP]

You can also try adding a statement to set the document's
ActiveWindow.Visible property to True.

You might also want to comment out any On Error Resume Next statement so you
can get a better handle on any errors that may be occurring.
 
L

Lori_CB

You are a goddess!

The ActiveWindow.Visible property and PrintPreview let me see the
information is on the form.

I added some message boxes so I know the form was filled out before the
PrintPreview statement and then after the PrintPreview statement.

When it hit the PrintOut statement, it cleared the form then did the actual
print.

Here's the code I used to test it.
' Print the Word document
msgbox "before preview"
oDoc.PrintPreview
msgbox "after preview"
oDoc.PrintOut
msgbox "after printout"

Now, I know it's the PrintOut statement that's causing the problem.

This has been driving me crazy for a week....thank you for saving my sanity.
 
S

Sue Mosher [MVP]

Wow, that sounds quite odd, but at least you can print it manually once you
have it in preview. You might want to ask in a Word forum about why the form
fields are clearing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top