Here is what i need it to do:
From Outlook 03 Custom Contact Form with User defined fields to go to a word doc and print out.
here is my alert message and not sure what to do or add to fix it:
Object variable not set: 'strMyField'
I worked on this all day yesterday and from this morning till now.. really frustrated...
please help.
thanks in advance
the Script:
Expand|Select|Wrap|Line Numbers
- Sub cmdPrint_Click()
- Set oWordApp = CreateObject("Word.Application")
- If oWordApp Is Nothing Then
- MsgBox "Couldn't start Word."
- Else
- Dim oWordDoc
- Dim bolPrintBackground
- ' Open a new document
- Set oDoc = oWordApp.Documents.Add("C:\MyForm.dot")
- ' Set the first bookmark to the contact's full name
- oDoc.FormFields("FullName").Result = CStr(Item.FullName)
- ' Set the second bookmark to the contact's address
- oDoc.FormFields("Address1").Result = CStr(Item.HomeAddressStreet)
- ' Set the second bookmark to the contact's address
- oDoc.FormFields("Address2").Result = CStr(Item.HomeAddressCity)
- ' Set the second bookmark to the contact's address
- oDoc.FormFields("State").Result = CStr(Item.HomeAddressState)
- ' Set the second bookmark to the contact's address
- oDoc.FormFields("Zip").Result = CStr(Item.HomeAddressPostalCode)
- ' Set the third bookmark to the contact's home phone
- oDoc.FormFields("Home").Result = CStr(Item.HomeTelephoneNumber)
- ' Set the Fourth bookmark to the contact's Email
- oDoc.FormFields("Email").Result = CStr(Item.Email1Address)
- ' Set the Fifth bookmark to the contact's Business
- oDoc.FormFields("Business").Result = CStr(Item.BusinessTelephoneNumber)
- ' Set the Sixth bookmark to the contact's Business2
- oDoc.FormFields("Business2").Result = CStr(Item.Business2TelephoneNumber)
- ' If the form contains user-defined fields, you can use
- ' the following syntax to transfer the contents of a
- ' user-defined field (FieldName) to Word:
- strMyField = Item.UserProperties.Find("TextBox31")
- oDoc.FormFields("AccountValue").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox12")
- oDoc.FormFields("Asof").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox32")
- oDoc.FormFields("OutlookUpdated").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox1")
- oDoc.FormFields("ClientName").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox4")
- oDoc.FormFields("RiskTolerance").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox2")
- oDoc.FormFields("ClientIDNumber").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox7")
- oDoc.FormFields("ClientDLNumber").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox8")
- oDoc.FormFields("ClientDLState").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox11")
- oDoc.FormFields("OSTProfileUpdated").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox3")
- oDoc.FormFields("ClientBirthday").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox6")
- oDoc.FormFields("ClientEmploymentStat").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox10")
- oDoc.FormFields("ClientSocialSecurity").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox9")
- oDoc.FormFields("WhenappClientDOD").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox23")
- oDoc.FormFields("Spouse").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox25")
- oDoc.FormFields("SPRiskTolerance").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox22")
- oDoc.FormFields("SpouseIDNumber").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox28")
- oDoc.FormFields("SPDLNumber").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox19")
- oDoc.FormFields("SPDLState").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox29")
- oDoc.FormFields("SPOSTProfileUpdated").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox21")
- oDoc.FormFields("SPBirthday").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox27")
- oDoc.FormFields("SpouseEmploymentSta").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox26")
- oDoc.FormFields("SpouseSocialSecurity").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox24")
- oDoc.FormFields("WhenAppSPDOD").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox13")
- oDoc.FormFields("GroupNumber").Result = strMyField
- strMyField = Item.UserProperties.Find("ComboBox1")
- oDoc.FormFields("ReviewType").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox14")
- oDoc.FormFields("ActualReviewDate").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox15")
- oDoc.FormFields("PreviousScheduledApp").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox16")
- oDoc.FormFields("CurrentYearScheduled").Result = strMyField
- strMyField = Item.UserProperties.Find("TextBox5")
- oDoc.FormFields("FollowUpAppt").Result = strMyField
- ' 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 don't 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