B
Bill Billmire
I am trying to print the data contents of a form in a for/next loop.
Searching for "bookmarks" in a word template is definitely the way to go. I
am having an issue with a standard field ("Sent"), what I want it to do is
(1st) find the field/bookmark in the word template named "Sent or Sentfield",
then set that bookmark field to the value of the (standard field) "Sent" in
the form. Right now what I have coded (in an "if" statement) only returns
the value of (True), so the 'If" statement bombs with RT error: "Object
variable not set" and does not set the value to the actual value of the field
in the form (i.e., Thur 12/9/2004 2:39 PM). Note: this code example comes
from that presented in
(http://www.outlookexchange.com/articles/home/lengho01.asp)
See code below...
'--------------------------Printing Routine--------------------------------
Dim strTemplate
Dim mybklist
Dim counter
Dim objWord
Dim objDocs
Dim strField
Dim strField1
Sub cmdPrint_Click()
Set objWord = CreateObject("Word.Application")
' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR1.dot"
' Location of Word template; could be on a shared LAN
strTemplate = "c:\windows\forms\" & strTemplate
Set objDocs = objWord.Documents
objDocs.Add strTemplate
set mybklist = objWord.ActiveDocument.Bookmarks
For counter = 1 to mybklist.count
If Item.UserProperties.Item("Sent") then 'code crashes here
Bookmark("Sent") = Item.Sent
End If
strField = objWord.ActiveDocument.Bookmarks(counter)
objWord.ActiveDocument.Bookmarks(strField).Select
strField1 = Item.UserProperties.find(strField).value
If strField1 = True then
strField1 = "Yes"
ElseIf strField1 = False then
strField1 = "No "
End If
objWord.Selection.TypeText Cstr(strField1)
Next
objWord.PrintOut Background = True
objWord.Quit(0)
End Sub
Searching for "bookmarks" in a word template is definitely the way to go. I
am having an issue with a standard field ("Sent"), what I want it to do is
(1st) find the field/bookmark in the word template named "Sent or Sentfield",
then set that bookmark field to the value of the (standard field) "Sent" in
the form. Right now what I have coded (in an "if" statement) only returns
the value of (True), so the 'If" statement bombs with RT error: "Object
variable not set" and does not set the value to the actual value of the field
in the form (i.e., Thur 12/9/2004 2:39 PM). Note: this code example comes
from that presented in
(http://www.outlookexchange.com/articles/home/lengho01.asp)
See code below...
'--------------------------Printing Routine--------------------------------
Dim strTemplate
Dim mybklist
Dim counter
Dim objWord
Dim objDocs
Dim strField
Dim strField1
Sub cmdPrint_Click()
Set objWord = CreateObject("Word.Application")
' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR1.dot"
' Location of Word template; could be on a shared LAN
strTemplate = "c:\windows\forms\" & strTemplate
Set objDocs = objWord.Documents
objDocs.Add strTemplate
set mybklist = objWord.ActiveDocument.Bookmarks
For counter = 1 to mybklist.count
If Item.UserProperties.Item("Sent") then 'code crashes here
Bookmark("Sent") = Item.Sent
End If
strField = objWord.ActiveDocument.Bookmarks(counter)
objWord.ActiveDocument.Bookmarks(strField).Select
strField1 = Item.UserProperties.find(strField).value
If strField1 = True then
strField1 = "Yes"
ElseIf strField1 = False then
strField1 = "No "
End If
objWord.Selection.TypeText Cstr(strField1)
Next
objWord.PrintOut Background = True
objWord.Quit(0)
End Sub