Re: OLK2K3: Programmatically setting checkboxes in printout to tem

From: Sue Mosher [MVP-Outlook] (suemvp_at_outlookcode.com)
Date: 01/10/05


Date: Mon, 10 Jan 2005 15:39:24 -0500

I see 3 problems:

1) Regarding this statement:

    If strField1 = "true" then

I see no earlier statement to set the value of strField1. Did you just omit
that in your latest post? We'll presume that it's a statement that gets the
value of an Outlook property.

2) Regarding that same statement, a Yes/No (i.e. Boolean) Outlook property
will never return a value of "true." The value will be either True or False,
in other words a logical value rather than an string (text) value.
Therefore, this statement should be:

    If strField1 = True then

3) This statement is prepending the "True" or "False" text:

    objMark.Range.InsertBefore strField1

You are applying it to all fields, rather than only to those fields that do
not return a value of True or False.

I'd suggest that you step away from the keyboard, get out pencil and paper
and write out a flow chart of how you want field values to be processed. Pay
attention to when you want the text inserted and when you want a check box
checked and the fact that you don't want both to happen for any one field.
Then rearrange your code statements so that the right statements take place
within the correct portions of your If ... End If blocks.

-- 
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:6B22FB22-3D7F-46A2-8E60-FE1F0E887EEC@microsoft.com...
> Hi Sue!
>
> Yes I have checkboxes with field names that match the bookmark names, and
> the Outlook form fields are bound to Yes/No properties.
>
> I used the following syntax to check the boxes, but they all get checked,
> and they are all still pre-pended with the True/False variable result.
> objDoc.FormFields(objMark.Name).CheckBox.Value = True
>
> As the loop iterates and finds each bookmark, it needs to determine if the
> Outlook field and reciprocal Bookmark go together then apply the
> ".CheckBox.Value = True" to check the correct template checkbox bookmark 
> (if
> true), all the rest (if false) get no checkmark for that bookmark.  Also, 
> not
> print the "true/false" variable result before the checkmark bookmark.
>
> In your opinion; should this logic be in an (If... Else If... End If) or a
> (Select Case... End Select) construct?
>
> '-------------------Printing Routine---------------------
> Dim objWord
> Dim strTemplate
> Dim strField
> Dim strField1
> Dim objDoc
> Dim objMark
> Dim mybklist
> Dim counter
>
> Sub cmdPrint_Click()
>
> Item.Save
> Set objWord = CreateObject("Word.Application")
>
> ' Put the name of the Word template that contains the bookmarks
> strTemplate = "FWR.dot"
>
> ' Location of Word template; could be on a shared LAN
> strTemplate = "\\ivory\forms\" & strTemplate
>
> Set objDoc = objWord.Documents.Add(strTemplate)
> Set mybklist = objDoc.Bookmarks
>
> For counter = 1 to mybklist.count
> Set objMark = objDoc.Bookmarks(counter)
> strField = objMark.Name
> If strField1 = "true" then
>     objDoc.FormFields(objMark.Name).CheckBox.Value = True
> Else If strfield1 = "false" then
>     strField1 = ""
> 'msgbox strField1
> Else
> 'msgbox strField
>     strField1 = Item.UserProperties(strField)
> 'msgbox strField1
> End If
> objMark.Range.InsertBefore strField1
> stop
> Next
> msgbox "Printing to " & objWord.ActivePrinter
> objDoc.PrintOut 0
> objWord.Quit(0)
> '     Clean up
>      Set objDoc = Nothing
>      Set objWord = Nothing
> End Sub
>
> Thanks again!
>
> Bill Billmire -
>
> "Sue Mosher [MVP-Outlook]" wrote:
>
>> Do you actually have check box fields set up with field names that match 
>> the
>> bookmark names? And are the checkboxes on the Outlook form bound to 
>> Yes/No
>> properties?
>>
>>
>> FYI, the syntax to check a check box associated with a bookmark is:
>>
>>     objDoc.FormFields(objMark.Name).CheckBox.Value = True
>> -- 
>> 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:F88F101D-1A3C-4B04-86C2-C5992E8DB6D0@microsoft.com...
>> >I have a custom (message based) form where I want to print the field 
>> >data.
>> >I
>> > have it working correctly for all fields except the "checkboxes".  The
>> > loop
>> > appears to iterate through all the bookmarks in the template correctly 
>> > and
>> > fills in the bookmarks with the exception of the checkboxes, instead of
>> > the
>> > checkboxes being "checked" they are prefixed with either True or False
>> > depending on the state of the checkbox in the Outlook form...  I want 
>> > the
>> > checkboxes on the word template to be either checked (or not checked) 
>> > as
>> > represented on the Outlook form.
>> >
>> > Code below...
>> >
>> > '----------------------Printing Routine------------------------
>> > Dim objWord
>> > Dim strTemplate
>> > Dim strField
>> > Dim strField1
>> > Dim objDoc
>> > Dim objMark
>> > Dim mybklist
>> > Dim counter
>> >
>> > Sub cmdPrint_Click()
>> >
>> > Item.Save
>> > Set objWord = CreateObject("Word.Application")
>> >
>> > ' Put the name of the Word template that contains the bookmarks
>> > strTemplate = "form.dot"
>> >
>> > ' Location of Word template; could be on a shared LAN
>> > strTemplate = "\\server\folder\" & strTemplate
>> >
>> > Set objDoc = objWord.Documents.Add(strTemplate)
>> > Set mybklist = objDoc.Bookmarks
>> >
>> > For counter = 1 to mybklist.count
>> > Set objMark = objDoc.Bookmarks(counter)
>> > strField = objMark.Name
>> > If strField = "SentField" then
>> >     strField1 = CStr(Item.SentOn)
>> > If strField = "ElectWork" then
>> > ObjMark("ElectWork").CheckBox.Value = True
>> > ElseIf strField = "Furniture" then
>> > ObjMark("Furniture").CheckBox.Value = True
>> > ElseIf strField = "GenConstruction" then
>> > ObjMark("GenConstruction").CheckBox.Value = True
>> > ElseIf strField = "Other" then
>> > ObjMark("Other").CheckBox.Value = True
>> > ElseIf strField = "PartitionRecon" then
>> > ObjMark("PartitionRecon").CheckBox.Value = True
>> > ElseIf strField = "PersonnelMove" then
>> > ObjMark("PersonnelMove").CheckBox.Value = True
>> > ElseIf strField = "Telecomm" then
>> > ObjMark("Telecomm").CheckBox.Value = True
>> > End If
>> > Else
>> >     strField1 = Item.UserProperties(strField)
>> > End If
>> > objMark.Range.InsertBefore strField1
>> > 'stop
>> > Next
>> > msgbox "Printing to " & objWord.ActivePrinter
>> > objDoc.PrintOut 0
>> > objWord.Quit(0)
>> > '     Clean up
>> >      Set objDoc = Nothing
>> >      Set objWord = Nothing
>> > End Sub
>> > -- 
>> >
>> > Thanks in advance!
>> > Bill Billmire
>>
>>
>> 


Relevant Pages

  • Re: OLK2K3: Form Printing Assistance (Standard Field).
    ... Is SentOn the name of a bookmark? ... Sue Mosher, Outlook MVP ... > strField gets set to "SentOn" ... > Dim strTemplate ...
    (microsoft.public.outlook.program_forms)
  • 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)