OLK2K3: Form Printing Assistance (Standard Field).

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
 
S

Sue Mosher [MVP-Outlook]

When in doubt, check the object browser: Press ALt+F11 to open the VBA
environment in Outlook, then press F2. Switch from <All Libraries> to
Outlook to browse all Outlook objects and their properties, methods, and
events. Select any object or member, then press F1 to see its Help topic.

You'll find that Sent is indeed a Boolean property, i.e. one with True or
False as its value. Perhaps the property you're looking for is SentOn, a
date property?
 
B

Bill Billmire

Thanks again Sue!
I ordered your book.

That was the correct object.property (i.e., SentOn), to return the date -
Thanks.
From the logic in the For/Next loop (and since the Standard Fields don't
behave in the same way as custom fields), I wanted to test the bookmarks
(using If/EndIf) in the template for the bookmark("Sent'), and when found,
insert the result from Item.SentOn for that bookmark, then proceed with the
rest of the bookmark/fields to eventually print the data.

Also, during the debugging/script failure, the "Just-in-Time Debugging"
Microsoft Script Editor dialog appears. Is there a way to add the VBA
development environment to the list of "Possible Debuggers"? The MS Script
Editor seems very limited in functionality.

Another question... During debugging, I would really like to see the
listing of "bookmarks" that the For/Next loop processes. So that I could
determine which bookmark/field is causing me problems as it cycles through
the counter. I Assume that "set mybklist =
objWord.ActiveDocument.Bookmarks", returns a listing? Otherwise, I put
msgbox strField and msgbox strField1, in the code; that results in a listing
of successful iterations, but not the one(s) that fail. The code seems to
iterate through the bookmarks pretty much alphabetically (a-z), skipping
some???, then it dies at the last bookmark with the error "The requested
member of the collection does not exist.". And dumps me into "Just-in-Time
Debugging" Microsoft Script Editor.

Thanks,

Bill Billmire -

Sue Mosher said:
When in doubt, check the object browser: Press ALt+F11 to open the VBA
environment in Outlook, then press F2. Switch from <All Libraries> to
Outlook to browse all Outlook objects and their properties, methods, and
events. Select any object or member, then press F1 to see its Help topic.

You'll find that Sent is indeed a Boolean property, i.e. one with True or
False as its value. Perhaps the property you're looking for is SentOn, a
date property?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Also, during the debugging/script failure, the "Just-in-Time Debugging"
Microsoft Script Editor dialog appears. Is there a way to add the VBA
development environment to the list of "Possible Debuggers"?

No, VBScript and VBA can't use the same debugger.
Another question... During debugging, I would really like to see the
listing of "bookmarks" that the For/Next loop processes. So that I could
determine which bookmark/field is causing me problems as it cycles through
the counter. I Assume that "set mybklist =
objWord.ActiveDocument.Bookmarks", returns a listing?

mybklist returns the Bookmarks *collection*. If you replace

strField = objWord.ActiveDocument.Bookmarks(counter)

with

Set objField = objWord.ActiveDocument.Bookmarks(counter)

you add objField to the Watch list in the debugger and get the Bookmark's
properties.

How did you set up your bookmarks in the document? Are they just insertion
points or do they include text?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Bill Billmire said:
Thanks again Sue!
I ordered your book.

That was the correct object.property (i.e., SentOn), to return the date -
Thanks.
From the logic in the For/Next loop (and since the Standard Fields don't
behave in the same way as custom fields), I wanted to test the bookmarks
(using If/EndIf) in the template for the bookmark("Sent'), and when found,
insert the result from Item.SentOn for that bookmark, then proceed with
the
rest of the bookmark/fields to eventually print the data.

Also, during the debugging/script failure, the "Just-in-Time Debugging"
Microsoft Script Editor dialog appears. Is there a way to add the VBA
development environment to the list of "Possible Debuggers"? The MS
Script
Editor seems very limited in functionality.

Another question... During debugging, I would really like to see the
listing of "bookmarks" that the For/Next loop processes. So that I could
determine which bookmark/field is causing me problems as it cycles through
the counter. I Assume that "set mybklist =
objWord.ActiveDocument.Bookmarks", returns a listing? Otherwise, I put
msgbox strField and msgbox strField1, in the code; that results in a
listing
of successful iterations, but not the one(s) that fail. The code seems to
iterate through the bookmarks pretty much alphabetically (a-z), skipping
some???, then it dies at the last bookmark with the error "The requested
member of the collection does not exist.". And dumps me into
"Just-in-Time
Debugging" Microsoft Script Editor.

Thanks,

Bill Billmire -
 
B

Bill Billmire

Thanks Sue - I received your book (and spent the last few days reading it).
It provided a lot of helpful information on a vast majority of questions and
issues I have been dealing with in creating (outlook forms) and
programmatically enhancing and customizing the Outlook/Exchange environment.

But I am still having issues with the printing aspect for this specific
form... It is basically an Information Technology (MIS) Service Request
(ticketing) system based on the message form. The Word Template that I am
trying to interface with just has bookmarks (insertion points) for the forms
field data. I have verified that the Word Template contains all the required
"bookmarks(insertion points)" needed to facilitate the Outlook Form fields.
Everything works on the form - except the printing function (which is new).

I don't code as a professional, so I do what I can and learn along the way.
But this printing issue really has me stumped. Do you know of any additional
code examples I could use (as/for) reference that specifically deal with
printing Outlook Form Data to a Word Template? Am I approaching this
solution in the correct way or is there another method that I can use to
print the Outlook form data? I am reading Chapter 22.3 "Sending output to
Microsoft Word", the code listing 22.10, looks way different than what I am
working with below (bottom of this thread). For reference: I using OLK2K3
and Word2K3.

In your last response you suggested that I modify the code as follows:

mybklist returns the Bookmarks *collection*. If you replace

strField = objWord.ActiveDocument.Bookmarks(counter)

with

Set objField = objWord.ActiveDocument.Bookmarks(counter)

You add objField to the Watch list in the debugger and get the Bookmark's
properties.

Adding the "objField" to the Watch List didn't provide me with the
"Bookmark's" properties only the reticent ellipse "(...)".

Thanks,

Bill Billmire -

Sue Mosher said:
No, VBScript and VBA can't use the same debugger.


mybklist returns the Bookmarks *collection*. If you replace

strField = objWord.ActiveDocument.Bookmarks(counter)

with

Set objField = objWord.ActiveDocument.Bookmarks(counter)

you add objField to the Watch list in the debugger and get the Bookmark's
properties.

How did you set up your bookmarks in the document? Are they just insertion
points or do they include text?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Sue Mosher, Outlook MVP

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
 
S

Sue Mosher [MVP-Outlook]

The code needs to be running before you'll see anything useful in the Watch
list. Set a breakpoint on the statement after you set the Bookmark object.

Why don't we concentrate on what issues you're still having? I can't tell
from your latest post what those might be. Did you try using any of the code
in the book -- look especially at the example for how the Body property is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body


--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bill Billmire

In the VBS Environment, setting breakpoints doesn't seem to provide the
effect I'm expecting.

The issues I am having are: I think the logic in the "Printing Routine", is
just wrong. I think the aspect of the [Standard Outlook Fields] has me
baffled, with respect to the For/Next loop. I know I need to test for the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result of this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

That line appears to provide me with the correct data, but I can't figure
out how to get the result back into the For/Next Loop, increment the counter
and continue with the next bookmark.

For counter = 1 to mybklist.count '(mybklist.count resolves to 14 in
Watch)
Item.UserProperties.Find("Sentfield").value = Item.SentOn '(Object
required error)
msgbox strField
msgbox strField1
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

Yes - I tried the code in the book, but that code doesn't use the For/Next
loop (For counter = 1 to mybklist.count), counter.

Also, in the outlook form I have two fields greater than 255 characters I
want to insert both into the Word Template... 1) Problem Description and 2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter Item.Body.

Thanks Sue!

Sue Mosher said:
The code needs to be running before you'll see anything useful in the Watch
list. Set a breakpoint on the statement after you set the Bookmark object.

Why don't we concentrate on what issues you're still having? I can't tell
from your latest post what those might be. Did you try using any of the code
in the book -- look especially at the example for how the Body property is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body


--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

In the VBS Environment, setting breakpoints doesn't seem to provide the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the script
debugger (Tools | Forms | Script Debugger) and add the breakpoint there.
The issues I am having are: I think the logic in the "Printing Routine",
is
just wrong. I think the aspect of the [Standard Outlook Fields] has me
baffled, with respect to the For/Next loop. I know I need to test for the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions of
Outlook, necessary) to use this syntax for the value of a custom property:

Item.UserProperties("Sentfield").
That line appears to provide me with the correct data, but I can't figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1
Also, in the outlook form I have two fields greater than 255 characters I
want to insert both into the Word Template... 1) Problem Description and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

 
B

Bill Billmire

Thanks Sue, your direction and suggestions helped quite a bit...

On the VBScript (breakpoint), I tried your suggestion, but when I navigate
to (Tools | Forms | Script Debugger), it's grayed out...

The following code now correctly loops through all the bookmarks in the Word
Template, with the exception of the "SentOn" Field/Bookmark. This is where I
believe I need to test for the condition "if strField = "SentOn" then...",
then process this differently...

strField gets set to "SentOn"
strField1 gets set to ""
Producing the following error during execution: [Object variable not set:
'strField1']

I believe that this field/bookmark needs an (If ... Then ... Else ... End
If) construct to handle the Outlook Standard Field (Item.SentOn). The (For
.... Next) loop sees the bookmark "SentOn" and doesn't know how to set it, or
handle it.

I still haven't gotten to the point where anything will print yet, so I
don't know about the remainder of the code.

Thanks,

Bill Billmire -
'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

Sue Mosher said:
In the VBS Environment, setting breakpoints doesn't seem to provide the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the script
debugger (Tools | Forms | Script Debugger) and add the breakpoint there.
The issues I am having are: I think the logic in the "Printing Routine",
is
just wrong. I think the aspect of the [Standard Outlook Fields] has me
baffled, with respect to the For/Next loop. I know I need to test for the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions of
Outlook, necessary) to use this syntax for the value of a custom property:

Item.UserProperties("Sentfield").
That line appears to provide me with the correct data, but I can't figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1
Also, in the outlook form I have two fields greater than 255 characters I
want to insert both into the Word Template... 1) Problem Description and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

 
S

Sue Mosher [MVP-Outlook]

Is SentOn the name of a bookmark? If so, change it to Sentfield so you can
use the solution I posted earlier:

If you do that, you won't need any special processing other than the line
above.

Maybe you didn't install the script debugger? Rerun Office setup. It's under
Office Tools / HTML Source Editing / Web Scripting / Web Debugging.
Intuitive, yes?

The remainder of the code still needs the adjustments I suggested in my last
post.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Bill Billmire said:
Thanks Sue, your direction and suggestions helped quite a bit...

On the VBScript (breakpoint), I tried your suggestion, but when I navigate
to (Tools | Forms | Script Debugger), it's grayed out...

The following code now correctly loops through all the bookmarks in the
Word
Template, with the exception of the "SentOn" Field/Bookmark. This is
where I
believe I need to test for the condition "if strField = "SentOn" then...",
then process this differently...

strField gets set to "SentOn"
strField1 gets set to ""
Producing the following error during execution: [Object variable not set:
'strField1']

I believe that this field/bookmark needs an (If ... Then ... Else ... End
If) construct to handle the Outlook Standard Field (Item.SentOn). The
(For
... Next) loop sees the bookmark "SentOn" and doesn't know how to set it,
or
handle it.

I still haven't gotten to the point where anything will print yet, so I
don't know about the remainder of the code.

Thanks,

Bill Billmire -
'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

Sue Mosher said:
In the VBS Environment, setting breakpoints doesn't seem to provide the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the script
debugger (Tools | Forms | Script Debugger) and add the breakpoint there.
The issues I am having are: I think the logic in the "Printing
Routine",
is
just wrong. I think the aspect of the [Standard Outlook Fields] has me
baffled, with respect to the For/Next loop. I know I need to test for
the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions of
Outlook, necessary) to use this syntax for the value of a custom
property:

Item.UserProperties("Sentfield").
That line appears to provide me with the correct data, but I can't
figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set
them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1
Also, in the outlook form I have two fields greater than 255 characters
I
want to insert both into the Word Template... 1) Problem Description
and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

:

The code needs to be running before you'll see anything useful in the
Watch
list. Set a breakpoint on the statement after you set the Bookmark
object.

Why don't we concentrate on what issues you're still having? I can't
tell
from your latest post what those might be. Did you try using any of
the
code
in the book -- look especially at the example for how the Body
property
is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body
 
B

Bill Billmire

Sue,

1) I changed the "bookmark" to read "Sentfield".
2) I reinstalled the "Office Tools / HTML Source Editing / Web Scripting /
Web Debugging", that now works. Thanks!
3) The loop blows up at the second to last iteration where the counter trys
to process the bookmark "Sentfield". The loop does not appear to know about
the "Item.UserProperties("Sentfield") = Item.SentOn"; instantiation earlier
in the code. The loop processes the bookmarks in (mybklist.count), and when
it gets to "SentField" it stops. [Object variable not set: 'strField1'] -
The loop tries to re-evaluate the "Sentfield" again, without any logic to
handle the "Outlook Standard Field => Item.SentOn". This is why I thought I
needed some logic to handle the [Item.SentOn]-[Standard Field] within, the
loop construct.
4) I believe I updated/modified the balance of the code per your earlier
recommendations. Let me know if you feel that I have missed any of your
suggestions in the updated code.

Thanks so much for all your assistance,

Bill Billmire -
(e-mail address removed)

Sue Mosher said:
Is SentOn the name of a bookmark? If so, change it to Sentfield so you can
use the solution I posted earlier:

If you do that, you won't need any special processing other than the line
above.

Maybe you didn't install the script debugger? Rerun Office setup. It's under
Office Tools / HTML Source Editing / Web Scripting / Web Debugging.
Intuitive, yes?

The remainder of the code still needs the adjustments I suggested in my last
post.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Bill Billmire said:
Thanks Sue, your direction and suggestions helped quite a bit...

On the VBScript (breakpoint), I tried your suggestion, but when I navigate
to (Tools | Forms | Script Debugger), it's grayed out...

The following code now correctly loops through all the bookmarks in the
Word
Template, with the exception of the "SentOn" Field/Bookmark. This is
where I
believe I need to test for the condition "if strField = "SentOn" then...",
then process this differently...

strField gets set to "SentOn"
strField1 gets set to ""
Producing the following error during execution: [Object variable not set:
'strField1']

I believe that this field/bookmark needs an (If ... Then ... Else ... End
If) construct to handle the Outlook Standard Field (Item.SentOn). The
(For
... Next) loop sees the bookmark "SentOn" and doesn't know how to set it,
or
handle it.

I still haven't gotten to the point where anything will print yet, so I
don't know about the remainder of the code.

Thanks,

Bill Billmire -
'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

Sue Mosher said:
In the VBS Environment, setting breakpoints doesn't seem to provide the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the script
debugger (Tools | Forms | Script Debugger) and add the breakpoint there.

The issues I am having are: I think the logic in the "Printing
Routine", is
just wrong. I think the aspect of the [Standard Outlook Fields] has me
baffled, with respect to the For/Next loop. I know I need to test for
the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions of
Outlook, necessary) to use this syntax for the value of a custom
property:

Item.UserProperties("Sentfield").

That line appears to provide me with the correct data, but I can't
figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set
them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1

Also, in the outlook form I have two fields greater than 255 characters
I
want to insert both into the Word Template... 1) Problem Description
and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


:

The code needs to be running before you'll see anything useful in the
Watch
list. Set a breakpoint on the statement after you set the Bookmark
object.

Why don't we concentrate on what issues you're still having? I can't
tell
from your latest post what those might be. Did you try using any of
the
code
in the book -- look especially at the example for how the Body
property
is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body
 
S

Sue Mosher [MVP-Outlook]

I think it would be helpful if you posted your latest code. What I see below
has both objMark.Range.InsertAfter strField1 and Selection.TypeText in it.
It also discerns the Yes/No values after Range.InsertAfter instead of
before.

When the code "blows up," what is the value of strField?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Bill Billmire said:
Sue,

1) I changed the "bookmark" to read "Sentfield".
2) I reinstalled the "Office Tools / HTML Source Editing / Web Scripting /
Web Debugging", that now works. Thanks!
3) The loop blows up at the second to last iteration where the counter
trys
to process the bookmark "Sentfield". The loop does not appear to know
about
the "Item.UserProperties("Sentfield") = Item.SentOn"; instantiation
earlier
in the code. The loop processes the bookmarks in (mybklist.count), and
when
it gets to "SentField" it stops. [Object variable not set: 'strField1'] -
The loop tries to re-evaluate the "Sentfield" again, without any logic to
handle the "Outlook Standard Field => Item.SentOn". This is why I thought
I
needed some logic to handle the [Item.SentOn]-[Standard Field] within, the
loop construct.
4) I believe I updated/modified the balance of the code per your earlier
recommendations. Let me know if you feel that I have missed any of your
suggestions in the updated code.

Thanks so much for all your assistance,

Bill Billmire -
(e-mail address removed)

Sue Mosher said:
Is SentOn the name of a bookmark? If so, change it to Sentfield so you
can
use the solution I posted earlier:
Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

If you do that, you won't need any special processing other than the line
above.

Maybe you didn't install the script debugger? Rerun Office setup. It's
under
Office Tools / HTML Source Editing / Web Scripting / Web Debugging.
Intuitive, yes?

The remainder of the code still needs the adjustments I suggested in my
last
post.


Bill Billmire said:
Thanks Sue, your direction and suggestions helped quite a bit...

On the VBScript (breakpoint), I tried your suggestion, but when I
navigate
to (Tools | Forms | Script Debugger), it's grayed out...

The following code now correctly loops through all the bookmarks in the
Word
Template, with the exception of the "SentOn" Field/Bookmark. This is
where I
believe I need to test for the condition "if strField = "SentOn"
then...",
then process this differently...

strField gets set to "SentOn"
strField1 gets set to ""
Producing the following error during execution: [Object variable not
set:
'strField1']

I believe that this field/bookmark needs an (If ... Then ... Else ...
End
If) construct to handle the Outlook Standard Field (Item.SentOn). The
(For
... Next) loop sees the bookmark "SentOn" and doesn't know how to set
it,
or
handle it.

I still haven't gotten to the point where anything will print yet, so I
don't know about the remainder of the code.

Thanks,

Bill Billmire -
'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

:

In the VBS Environment, setting breakpoints doesn't seem to provide
the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the
script
debugger (Tools | Forms | Script Debugger) and add the breakpoint
there.

The issues I am having are: I think the logic in the "Printing
Routine", is
just wrong. I think the aspect of the [Standard Outlook Fields] has
me
baffled, with respect to the For/Next loop. I know I need to test
for
the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result
of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions
of
Outlook, necessary) to use this syntax for the value of a custom
property:

Item.UserProperties("Sentfield").

That line appears to provide me with the correct data, but I can't
figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs
to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set
them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the
new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1

Also, in the outlook form I have two fields greater than 255
characters
I
want to insert both into the Word Template... 1) Problem Description
and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter
Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


:

The code needs to be running before you'll see anything useful in
the
Watch
list. Set a breakpoint on the statement after you set the Bookmark
object.

Why don't we concentrate on what issues you're still having? I
can't
tell
from your latest post what those might be. Did you try using any of
the
code
in the book -- look especially at the example for how the Body
property
is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body
 
B

Bill Billmire

Sue,

Latest Code...

'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

Thanks!

Bill Billmire -
(e-mail address removed)

Sue Mosher said:
I think it would be helpful if you posted your latest code. What I see below
has both objMark.Range.InsertAfter strField1 and Selection.TypeText in it.
It also discerns the Yes/No values after Range.InsertAfter instead of
before.

When the code "blows up," what is the value of strField?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Bill Billmire said:
Sue,

1) I changed the "bookmark" to read "Sentfield".
2) I reinstalled the "Office Tools / HTML Source Editing / Web Scripting /
Web Debugging", that now works. Thanks!
3) The loop blows up at the second to last iteration where the counter
trys
to process the bookmark "Sentfield". The loop does not appear to know
about
the "Item.UserProperties("Sentfield") = Item.SentOn"; instantiation
earlier
in the code. The loop processes the bookmarks in (mybklist.count), and
when
it gets to "SentField" it stops. [Object variable not set: 'strField1'] -
The loop tries to re-evaluate the "Sentfield" again, without any logic to
handle the "Outlook Standard Field => Item.SentOn". This is why I thought
I
needed some logic to handle the [Item.SentOn]-[Standard Field] within, the
loop construct.
4) I believe I updated/modified the balance of the code per your earlier
recommendations. Let me know if you feel that I have missed any of your
suggestions in the updated code.

Thanks so much for all your assistance,

Bill Billmire -
(e-mail address removed)

Sue Mosher said:
Is SentOn the name of a bookmark? If so, change it to Sentfield so you
can
use the solution I posted earlier:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

If you do that, you won't need any special processing other than the line
above.

Maybe you didn't install the script debugger? Rerun Office setup. It's
under
Office Tools / HTML Source Editing / Web Scripting / Web Debugging.
Intuitive, yes?

The remainder of the code still needs the adjustments I suggested in my
last
post.


Thanks Sue, your direction and suggestions helped quite a bit...

On the VBScript (breakpoint), I tried your suggestion, but when I
navigate
to (Tools | Forms | Script Debugger), it's grayed out...

The following code now correctly loops through all the bookmarks in the
Word
Template, with the exception of the "SentOn" Field/Bookmark. This is
where I
believe I need to test for the condition "if strField = "SentOn"
then...",
then process this differently...

strField gets set to "SentOn"
strField1 gets set to ""
Producing the following error during execution: [Object variable not
set:
'strField1']

I believe that this field/bookmark needs an (If ... Then ... Else ...
End
If) construct to handle the Outlook Standard Field (Item.SentOn). The
(For
... Next) loop sees the bookmark "SentOn" and doesn't know how to set
it,
or
handle it.

I still haven't gotten to the point where anything will print yet, so I
don't know about the remainder of the code.

Thanks,

Bill Billmire -
'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

:

In the VBS Environment, setting breakpoints doesn't seem to provide
the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the
script
debugger (Tools | Forms | Script Debugger) and add the breakpoint
there.

The issues I am having are: I think the logic in the "Printing
Routine", is
just wrong. I think the aspect of the [Standard Outlook Fields] has
me
baffled, with respect to the For/Next loop. I know I need to test
for
the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result
of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions
of
Outlook, necessary) to use this syntax for the value of a custom
property:

Item.UserProperties("Sentfield").

That line appears to provide me with the correct data, but I can't
figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs
to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set
them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the
new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1

Also, in the outlook form I have two fields greater than 255
characters
I
want to insert both into the Word Template... 1) Problem Description
and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter
Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


:

The code needs to be running before you'll see anything useful in
the
Watch
list. Set a breakpoint on the statement after you set the Bookmark
object.

Why don't we concentrate on what issues you're still having? I
can't
tell
from your latest post what those might be. Did you try using any of
the
code
in the book -- look especially at the example for how the Body
property
is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body
 
B

Bill Billmire

Line that errors out, and variables set to...

strField1 = Item.UserProperties(strField)

strField = "SentField"
strField1 = "1234.567"

Bill Billmire -

Bill Billmire said:
Sue,

Latest Code...

'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

Thanks!

Bill Billmire -
(e-mail address removed)

Sue Mosher said:
I think it would be helpful if you posted your latest code. What I see below
has both objMark.Range.InsertAfter strField1 and Selection.TypeText in it.
It also discerns the Yes/No values after Range.InsertAfter instead of
before.

When the code "blows up," what is the value of strField?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Bill Billmire said:
Sue,

1) I changed the "bookmark" to read "Sentfield".
2) I reinstalled the "Office Tools / HTML Source Editing / Web Scripting /
Web Debugging", that now works. Thanks!
3) The loop blows up at the second to last iteration where the counter
trys
to process the bookmark "Sentfield". The loop does not appear to know
about
the "Item.UserProperties("Sentfield") = Item.SentOn"; instantiation
earlier
in the code. The loop processes the bookmarks in (mybklist.count), and
when
it gets to "SentField" it stops. [Object variable not set: 'strField1'] -
The loop tries to re-evaluate the "Sentfield" again, without any logic to
handle the "Outlook Standard Field => Item.SentOn". This is why I thought
I
needed some logic to handle the [Item.SentOn]-[Standard Field] within, the
loop construct.
4) I believe I updated/modified the balance of the code per your earlier
recommendations. Let me know if you feel that I have missed any of your
suggestions in the updated code.

Thanks so much for all your assistance,

Bill Billmire -
(e-mail address removed)

:

Is SentOn the name of a bookmark? If so, change it to Sentfield so you
can
use the solution I posted earlier:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

If you do that, you won't need any special processing other than the line
above.

Maybe you didn't install the script debugger? Rerun Office setup. It's
under
Office Tools / HTML Source Editing / Web Scripting / Web Debugging.
Intuitive, yes?

The remainder of the code still needs the adjustments I suggested in my
last
post.
Thanks Sue, your direction and suggestions helped quite a bit...

On the VBScript (breakpoint), I tried your suggestion, but when I
navigate
to (Tools | Forms | Script Debugger), it's grayed out...

The following code now correctly loops through all the bookmarks in the
Word
Template, with the exception of the "SentOn" Field/Bookmark. This is
where I
believe I need to test for the condition "if strField = "SentOn"
then...",
then process this differently...

strField gets set to "SentOn"
strField1 gets set to ""
Producing the following error during execution: [Object variable not
set:
'strField1']

I believe that this field/bookmark needs an (If ... Then ... Else ...
End
If) construct to handle the Outlook Standard Field (Item.SentOn). The
(For
... Next) loop sees the bookmark "SentOn" and doesn't know how to set
it,
or
handle it.

I still haven't gotten to the point where anything will print yet, so I
don't know about the remainder of the code.

Thanks,

Bill Billmire -
'----------------------Printing Routine--------------------------
Dim objWord
Dim strTemplate
Dim objDocs
Dim objDoc
Dim objMark
Dim mybklist
Dim counter
Dim objField
Dim strField
Dim strField1

Sub cmdPrint_Click()

Set objWord = CreateObject("Word.Application")

' Put the name of your Word template that contains the bookmarks
strTemplate = "OSR.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

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties(strField)
msgbox strField ' these are temporary while debugging the routine
msgbox strField1 ' these are temporary while debugging the routine
Set objDoc = objDocs.Add(strTemplate)
Set objMark = objWord.ActiveDocument.Bookmarks(counter)
objMark.Range.InsertAfter strField1
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

:

In the VBS Environment, setting breakpoints doesn't seem to provide
the
effect I'm expecting.

For VBScript, either put a Stop statement in the code or start the
script
debugger (Tools | Forms | Script Debugger) and add the breakpoint
there.

The issues I am having are: I think the logic in the "Printing
Routine", is
just wrong. I think the aspect of the [Standard Outlook Fields] has
me
baffled, with respect to the For/Next loop. I know I need to test
for
the
"Standard Outlook Field.SentOn", and handle it differently than the
Custom/User Defined fields. I don't know how to handle the result
of
this:

Item.UserProperties.Find("Sentfield").value = Item.SentOn

Note that it's perfectly acceptable and easier (and in some versions
of
Outlook, necessary) to use this syntax for the value of a custom
property:

Item.UserProperties("Sentfield").

That line appears to provide me with the correct data, but I can't
figure
out how to get the result back into the For/Next Loop, increment the
counter
and continue with the next bookmark.

That statement has nothing to do with the For ... Next loop and needs
to
preceed it:

Item.UserProperties("Sentfield") = Item.SentOn
For counter = 1 to mybklist.count

These statements are out of order:

msgbox strField
msgbox strField1
strField = objWord.ActiveDocument.Bookmarks(counter)
strField1 = Item.UserProperties.Find(strField).value

You want to check the value of strField1 and strField, after you set
them,
not before:

Set objMark = obj.Bookmarks(counter)
strField = objMark.Name
strField1 = Item.UserProperties.(strField)
msgbox strField
msgbox strField1

Note that you'll use the objMark object again below.

This is not the best way to insert text at zero-length bookmark:

objWord.ActiveDocument.Bookmarks(strField).Select
objWord.Selection.TypeText Cstr(strField1)

Instead, do it this way, having earlier set an object variable to the
new
document:

Set objDoc = objDocs.Add(strTemplate)
' more of your code here

then within the For ... Next loop, inserting text at each bookmark:

Set objMark = obj.Bookmarks(counter)
objMark.Range.InsertAfter strField1

Also, in the outlook form I have two fields greater than 255
characters
I
want to insert both into the Word Template... 1) Problem Description
and
2)
Corrective Action(s), for objDoc.Bookmark.Range.InsertAfter
Item.Body.

Use the same InsertAfter syntax as above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


:

The code needs to be running before you'll see anything useful in
the
Watch
list. Set a breakpoint on the statement after you set the Bookmark
object.

Why don't we concentrate on what issues you're still having? I
can't
tell
from your latest post what those might be. Did you try using any of
the
code
in the book -- look especially at the example for how the Body
property
is
inserted for a bookmark:

objDoc.Bookmark.Range.InsertAfter Item.Body
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top