Stumped - trying to created message box w/outlook 2002 template I have been spending several hours on project - and have 1 part left which I just can't figure out.
I have designed a new form in outlook 2002. Most of the fields are user-defined drop downs and checkboxes and we have been able to write vba script to push the information into a Word template. My problem is trying to create a "message box" at the end of the form, where the user can type in their summary - and then have that print out to the word template. In the outlook form - we have dragged the "message" field from the Field chooser box and placed in our the form. On the corresponding word document, we have inserted a bookmark and used the command {SET boomark: Message}.
Within the vba script we have included the line :
objDoc.Bookmarks("Message").Range.Insert AfterItem Body. That is the sentence verbatim.
With this combination, I keep getting an error that the ObjDoc is not defined.
I've tried making changes for several hours, but have not been able to figure out what to do. I am taking the liberty of including the entire code -- hopefully someone can help me get this last piece working. It is the 8th bookmark located towards the end. ANY HELP GREATLY APPRECIATED!!!
Sub cmdPrint_Click()
Dim oWordApp
Dim oWordDoc
Dim bolPrintBackground
Dim objProp
Set oWordApp=CreateObject ("Word.Application")
If oWordApp Is Nothing Then
MsgBox "Couldn't start Word."
Exit Sub
End If
'Open a new document
Set oDoc = oWordApp.Documents.Add ("O:\Public\LegalRegulatory\ReferenceMaterials\MyForm77.dot")
'Set the first bookmark to the Market name
Set objProp=Item.UserProperties("A. Market")
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text1"). Result = objProp.Value
End If
End If
'Set the second bookmark to Manager
Set objProp=Item.UserProperties("B. Regulatory Manager")
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text2"). Result = objProp.Value
End If
End If
'Set the third bookmark to Subject
oDoc.FormFields("Text16"). Result = CStr(Item.Subject)
'Get my value via my control.Value
MyValue= Item.UserProperties("G. Benefits").Value
If MyValue = True Then
MyValue = "*Benefits"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text3"). Result = MyValue
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("H. Claims").Value
If MyValue = True Then
MyValue = "*Claims"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text4"). Result = MyValue
End If
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("I. Complaints/Appeals").Value
If MyValue = True Then
MyValue = "*Complaints/Appeals"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text5"). Result = MyValue
End If
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("J. Eligibility").Value
If MyValue = True Then
MyValue = "*Eligibility"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text6"). Result = MyValue
End If
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("K. Fees/Rates").Value
If MyValue = True Then
MyValue = "*Fees/Rates"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text7"). Result = MyValue
End If
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("L. Fee For Service Changes").Value
If MyValue = True Then
MyValue = "*Fee For Service Changes"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text8"). Result = MyValue
End If
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("M. Other").Value
If MyValue = True Then
MyValue = "*Other"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text9"). Result = MyValue
End If
End If
'Get my value via my control.Value
MyValue= Item.UserProperties("N. Reporting").Value
If MyValue = True Then
MyValue = "*Reporting"
Else
MyValue = "***"
End If
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text10"). Result = MyValue
End If
End If
'Set the fourth bookmark to the Document Status
Set objProp=Item.UserProperties("C. Document Status")
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text11"). Result = objProp.Value
End If
End If
'Set the fifth bookmark to the Effective Date
Set objProp=Item.UserProperties("D. Effective Date")
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text12"). Result = objProp.Value
End If
End If
'Set the sixth bookmark to the Action Required
Set objProp=Item.UserProperties("E. Action Required")
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text13"). Result = objProp.Value
End If
End If
'Set the seventh bookmark to the Response Needed by
Set objProp=Item.UserProperties("F. Response Needed by")
If not objProp Is Nothing Then
If objProp.Type <> olKeywords Then
oDoc.FormFields("Text14"). Result = objProp.Value
End If
End If
'Set the 8th bookmark to the Message
Set objDoc.Bookmarks =("Message") Range. InsertAfter Item.Body
'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 oPS = Nothing
Set oDoc = Nothing
Set oWordApp = Nothing
End If
End Sub |