Printing Outlook Form Controls via Word

Status
Not open for further replies.

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Howdy all. I've been following advice from various forums but I cannot seem to get it working. The overly simplfied version of what I am doing is as follows:

I have a Label in word called "projectName" who's caption is blank. I have a textbox in Outlook called "projectName". I want to hit the button on the form and send the value in the textbox to that label in word, and then print the word document. If someone could help me correct the line I've made obvious I would appreciate it (also if there's errors below it I'd appreciate the heads up). All I have is textboxes, checkboxes and comboboxes in the form.

Code:
Sub printButton_Click() 
 
Set oWordApp = CreateObject("Word.Application") 
 
Set FormPage = Item.GetInspector.ModifiedFormPages("Message") 
 
If oWordApp Is Nothing Then
    MsgBox "Couldn't start Word." 
 
Else
   MsgBox "Could Start Word."
   Dim oWordApp
   Dim oWordDoc
   Dim bolPrintBackground 
 
' Open a new document. 
 
Set oDoc = oWordApp.Documents.Add("C:\Scratchpad\Survey_Request_Form_Print_Template.dotm") 
 
'Set the first bookmark to the contact's full name. 
 
'********** THIS LINE IS BORKED **********
   oDoc.FormFields("projectName").Label = CStr(FormPage.Controls("projectName").Text) 
 
'********** THIS LINE IS BORKED ********** 
 
 
   ' 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 
 
' Restore previous setting.
   oWordApp.Options.PrintBackground = bolPrintBackground 
 
 
   ' Close and do not save changes to the document.
   Const wdDoNotSaveChanges = 0
   oDoc.Close wdDoNotSaveChanges 
 
 
   ' Close the Word instance.
   oWordApp.Quit 
 
'Clean up.
   Set oDoc = Nothing
   Set oWordApp = Nothing 
 
End If 
 
End Sub
 

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Bump - could really do with help here. Been stalled out on this for a week

Cheers guys
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sorry about that - i was out of town and my helpers aren't very good at helping. :(

I'm not sure if you can insert into label fields, I've only inserted into bookmarks and text fields. Did you try assigning the string to a variable then insert it -
strMyField = CStr(FormPage.Controls("projectName").Text)
oDoc.FormFields("projectName").Label = strMyField
 

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
oDoc.FormFields("projectName").Label = strMyField

This line returned a "The requested member of the collection does not exist." Therefore it would seem your uncertainty was well founded! I swapped to Plain Text Controls and it worked wonders.

Thanks for your help :)
 

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Sorry for the triple post. New problem same code.

There is a print button on the form which calls the template. It works on the originating computer, but not on the recieving computer. Hitting "Develop This Form' shows the code correctly sends, and the code has error MsgBoxs which are not popping up. I can post the code if it helps, but it's 8000 characters and therefore exceeds the 4000 character limit on this forum.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Do you have macro security set to low? That is #1 cause of code not working. If the code is running (so its not macro security) , comment out all of the error handlers and run it or step through it to see where it stops.
 

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
I'll check tomorrow, I have not changed that setting because I was unaware it existed.

I should point out that I can use the code when running the form with the "Run This Form" option inside "Design This Form". That's how I didn't discover my issue until I sent it for testing
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
if the code works inside run this firm, it's not macro security. Is the form published or opened from the Choose Form dialog? Because it has script behind it, you need to open it using the Choose Forms dialog or publish it. Outlook will usually popup a warning about this though.
 

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Choose form option was chosen on the test clients.

The button isn't even doing anything; on a different program altogether we had to enable the code to send along it's identity, otherwise the client didn't know the button was actually called printButton etc. In Outlook do we have to alter anything to send definitions of objects?
 

CruciasNZ

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
It seems the form had to be published to each individual clients Form Directory inside outlook in order for my printing code to function.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Correct, it needs published - that is a security feature of outlook. If you use Exchange server it could be published to the organizational forms library, but with other accounts every user needs to publish it.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
T Printing from Outlook is now defaulting to "Shrink to Fit"! Using Outlook 5
S Outlook 2007 printing wrong email address at top of page Using Outlook 8
P Printing PDF attachments of Outlook message attachments Outlook VBA and Custom Forms 2
P printing weekly calendar in Outlook 2013 cuts days of week off Using Outlook 1
G booklet printing in outlook 2007 Using Outlook 1
M Outlook 2013 is printing headers only Using Outlook 4
D Printing Attachments Automatically in Outlook 2010 Using Outlook 1
J outlook printing Using Outlook 2
J Printing Calendar in Outlook 2013 Using Outlook 0
K Printing & Saving Outlook Contacts Using Outlook 3
P Printing Issues in Outlook 2007 Using Outlook 1
E Outlook 2010 network printing problems Using Outlook 4
L Auto printing unread email + attachments in Inbox - Outlook 2010 - (New user) Using Outlook 1
S How to remove tracking from printing - outlook 2010 Using Outlook 4
A Outlook CPAO - Printing Monthly calendar with only all day events or catergory Calendar Printing Assistant 2
M Outlook 2010 task line printing Using Outlook 1
A outlook printing assistant Help editing template Calendar Printing Assistant 3
W Calendar Printing with Outlook 2010 (64 bit) Calendar Printing Assistant 1
J Outlook 2003 - Tasks - Printing Notes Using Outlook 1
R Header not printing in Outlook 2010 Using Outlook 3
P Printing problems with MS Outlook 2000 Using Outlook 1
A Emailing Calendars Created in Outlook Calendar Printing Assistant Calendar Printing Assistant 3
J Microsoft Outlook Calendar - end time of appointment has started printing but don't want it to print Using Outlook 2
C Calendar Printing Assistant for Outlook 2010 Using Outlook 2
1 printing from outlook Using Outlook 2
B Outlook - Printing - RTF Email Attachment Icon and Name Problems. Using Outlook 2
R Printing Outlook Contacts to Label Sheet Using Outlook 2
R How do I use Outlook 2007 for printing a label list for a specific category Using Outlook 3
W res://ieframe.dll/preview.js error printing from outlook 2003 Using Outlook 2
D Outlook 2010 printing a column per page instead of the month Using Outlook 1
D Trouble downloading Calendar Printing Assistant for Outlook 2010 Using Outlook 2
J Printing Outlook Contacts as addresses on envelopes Using Outlook 1
M Contacting server for information while printing HTML in Outlook 2010 Using Outlook 1
T Outlook 2010 turn OFF background color when printing Using Outlook 3
G Using Outlook Calendar Printing Assistant in Outlook 2010 Using Outlook 6
D Printing Multiple Attachments Outlook 2007 Using Outlook 1
Y Outlook 2010 or Calendar Printing Assistant Calendar Printing Assistant 2
W Automatically open attachments without automatically printing them Using Outlook 0
snissen Printing foreign language messages Using Outlook 1
L printing contacts Using Outlook 1
A How to get rid of Contacts field when printing emails? Using Outlook 0
Diane Poremsky Printing Calendars with Color Categories New Slipstick.com Articles 0
D VBA macro printing attachments in shared mailbox Outlook VBA and Custom Forms 1
D Printing Contacts Using Outlook 2
C Printing tasks with multiple categories Using Outlook 5
S macro for opening attachments and printing Using Outlook 1
J Printing Mulitple Calendars Outlook VBA and Custom Forms 1
M Calendar Printing Assistant Hangs only on specific Template Using Outlook 2
W Meeting printing background fields Using Outlook 0
K calendar printing Using Outlook 1

Similar threads

Top