Re: OLK2K3: Form Printing Assistance (Standard Field).

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Sue Mosher [MVP-Outlook] (suemvp_at_outlookcode.com)
Date: 12/23/04


Date: Thu, 23 Dec 2004 15:00:57 -0500

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.

-- 
Sue Mosher, Outlook MVP
Author of
     Microsoft Outlook Programming - Jumpstart for
     Administrators, Power Users, and Developers
     http://www.outlookcode.com/jumpstart.aspx
"Bill Billmire" <BillBillmire@discussions.microsoft.com> wrote in message 
news:3C3BACCA-9DAB-4619-9D16-6700DE4DE692@microsoft.com...
> 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 [MVP-Outlook]" wrote:
>
>> > 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
>>      http://www.outlookcode.com/jumpstart.aspx
>>
>> > "Sue Mosher [MVP-Outlook]" wrote:
>> >
>> >> 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


Relevant Pages

  • Re: OLK2K3: Programmatically setting checkboxes in printout to tem
    ... a Yes/No Outlook property ... > As the loop iterates and finds each bookmark, it needs to determine if the ... > Dim strTemplate ... > strField = objMark.Name ...
    (microsoft.public.outlook.program_vba)
  • Re: Problems accesing created bookmark in VBA
    ... I could actually create a normal bookmark (non hidden as ... Michael Bauer - MVP Outlook ... Dim WithEvents oAppInspectors As Outlook.Inspectors ... Dim colCBControls As Office.CommandBarControls ...
    (microsoft.public.outlook.program_vba)
  • Re: OLK2K3: Standard Field Printing Issue
    ... then the name of the bookmark must not be SentField. ... the value of strField. ... inside the loop: ... >>> Dim strTemplate ...
    (microsoft.public.outlook.program_forms)
  • Re: OLK2K3: Programmatically setting checkboxes in printout to tem
    ... ElseIf strfield1 = False then ... Sue Mosher, Outlook MVP ... > Dim strTemplate ... >>> Yes I have checkboxes with field names that match the bookmark names, ...
    (microsoft.public.outlook.program_vba)
  • Re: OLK2K3: Form Printing Assistance (Standard Field).
    ... You want to check the value of strField1 and strField, after you set them, ... This is not the best way to insert text at zero-length bookmark: ... I have verified that the Word Template contains all the ... >>> Dim strTemplate ...
    (microsoft.public.outlook.program_forms)