Re: OLK2K3: Form Printing Assistance (Standard Field).
From: Sue Mosher [MVP-Outlook] (suemvp_at_outlookcode.com)
Date: 12/23/04
- Next message: robert: "custom fields in mail merge"
- Previous message: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- In reply to: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- Next in thread: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- Reply: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 22 Dec 2004 20:55:03 -0500
> 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
>>
>> "Bill Billmire" <BillBillmire@discussions.microsoft.com> wrote in message
>> news:2B7DB5B9-3AD2-4E72-844F-6D90D8FC06F4@microsoft.com...
>> >
>> > 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 [MVP-Outlook]" wrote:
>> >> >
>> >> > 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 [MVP-Outlook]" wrote:
>> >> >
>> >> >> 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
>> >
>> > "Bill Billmire" <BillBillmire@discussions.microsoft.com> wrote in
>> > message
>> > news:1B7E5F15-3A5C-4DE9-BA76-838AB5B871A0@microsoft.com...
>> > 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
>> >
>> > --
>> >
>> > Thanks!
>> > Bill Billmire
>>
>>
>>
- Next message: robert: "custom fields in mail merge"
- Previous message: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- In reply to: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- Next in thread: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- Reply: Bill Billmire: "Re: OLK2K3: Form Printing Assistance (Standard Field)."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|