Trying to Printing Outlook 2013 form through Word issues

I am new to Outlook programming and am trying to print a form from Outlook 2013.  It defaults to printing a summary version of the form, which is not what I want.  I saw a previous post in this forum about using Outlook to open up and print the form correctly from Word.

I am having issues if I run the form as a macro, it will open up in Word, however the data will not pull in.  I do get an error that is labeled Microsoft Visual Basic and the error is Run-time error '91'.  Object variable or With block variable not set.  Here is my script and I have the word template attached as well.  Can someone help me or point me in the right direction?

Sub printOrSave
    ' Print or preview the Word document
     Dim oWordApp ' As Word.Application
     Dim strMyField ' As String
     Dim oDoc ' As Word.Document
     Dim bolPrintBackground
     Set oWordApp = CreateObject("Word.Application")
     If oWordApp Is Nothing Then
     MsgBox "Couldn't start Word."
     oWordApp.Visible = True
     ' Open a new document
    Set olkMsg = Application.ActiveInspector.CurrentItem

     Set oDoc = oWordApp.Documents.Add("C:\", True, , True)
                                    'Template, NewTemplate, DocumentType, Visible
   'Map the data in the Outlook form the the field in the word template
    ' Set the first bookmark to the To Field

    oDoc.Bookmarks("txtTo").Result = olkMsg.UserProperties.Item("txtTo").Value
    oDoc.FormFields("txtCC").Result = olkMsg.UserProperties.Item("txtCC").Value
    oDoc.FormFields("txtSubject").Result = olkMsg.UserProperties.Item("txtSubject").Value
    oDoc.FormFields("ddChangeReason").Result = olkMsg.UserProperties.Item("dddChangeReason").Value
    oDoc.FormFields("ckbxAllWeekDays").Result = olkMsg.UserProperties.Item("ckbxAllWeekDays").Value
    oDoc.FormFields("ckbxAll").Result = olkMsg.UserProperties.Item("ckbxAll").Value
    oDoc.FormFields("ckbxSunday").Result = olkMsg.UserProperties.Item("ckbxSunday").Value
    oDoc.FormFields("ckbxMonday").Result = olkMsg.UserProperties.Item("ckbxMonday").Value
    oDoc.FormFields("ckbxTuesday").Result = olkMsg.UserProperties.Item("ckbxTuesday").Value
    oDoc.FormFields("ckbxWednesday").Result = olkMsg.UserProperties.Item("ckbxWednesday").Value
    oDoc.FormFields("ckbxThursday").Result = olkMsg.UserProperties.Item("ckbxThursday").Value
    oDoc.FormFields("ckbxTRIA").Result = olkMsg.UserProperties.Item("ckbxTRIA").Value
    oDoc.FormFields("ckbxFriday").Result = olkMsg.UserProperties.Item("ckbxFriday").Value
    oDoc.FormFields("ckbxSaturday").Result = olkMsg.UserProperties.Item("ckbxSaturday").Value
    oDoc.FormFields("ckbxWeekendsOnly").Result = olkMsg.UserProperties.Item("ckbxWeekendsOnly").Value
    oDoc.FormFields("txtEDOC").Result = olkMsg.UserProperties.Item("txtEDOC").Value
    oDoc.FormFields("txtChangeInfo").Result = olkMsg.UserProperties.Item("txtChangeInfo").Value

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

     ' Turn background printing off
   oWordApp.Options.PrintBackground = False
    If action = "print" Then

    ' Restore previous setting
         oWordApp.Options.PrintBackground = bolPrintBackground

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

         ' Close the Word instance

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

Open in new window
Word HelpAsked:
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
In Word, a bookmark object does not have a .Result property or method. Try using  .Range.Text  instead
 oDoc.Bookmarks("txtTo").Range.Text = olkMsg.UserProperties.Item("txtTo").Value

Open in new window

Word HelpAuthor Commented:
Thank you so much for the help.  Where can I find out more information about properties/methods and also how to use them?  I have tried reading the information out on msdn but it is not easy to understand how to use them.  I have been piecing things together here and there.  

Using the .Range.Text worked for my text boxes but I also have some check boxes as well as a drop down box.
I get a runtime error 91 Object variable or With block variable not set error when I use this:
    oDoc.Bookmarks("All").Range.Value = olkMsg.UserProperties.Item("ckbxAll").Value

Can you point me to what type of code to use for checkbox values and drop down values?
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.