Re: OLK2K3: Programmatically setting checkboxes in printout to tem

From: Bill Billmire (BillBillmire_at_discussions.microsoft.com)
Date: 01/10/05


Date: Mon, 10 Jan 2005 13:59:07 -0800

Thanks Sue,

I already had the routine fully architected, but my limited knowledge of
VBScripting and all the functions and arguments available and correct usage
make me stumble quite a bit.

The following code now works as I expected it to, (please review and comment
if you see anything wrong or can suggest better ways to accomplish the same
thing).

'----------------------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
                   strField1 = Item.UserProperties(strField)

                   If strField1 = True then
                   objDoc.FormFields(objMark.Name).CheckBox.Value = True
                   End If
                
                   If strfield1 = False then
                   objDoc.FormFields(objMark.Name).CheckBox.Value = False
                           End If
                
                   If VarType(strField1) = 8 then
                   objMark.Range.InsertBefore strField1
                   End If
        Next
msgbox "Printing to " & objWord.ActivePrinter
        objDoc.PrintOut 0
        objWord.Quit(0)
' Clean up
      Set objDoc = Nothing
      Set objWord = Nothing
End Sub

Thanks,

"Sue Mosher [MVP-Outlook]" wrote:

> 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: DocOutlook Landkarte Deutschland
    ... Informationen von Smarttools Outlook Weekly vom 11/19/25.02.2004 ... Karten und Routenplanung direkt aus Outlook aufrufen, ... ByVal Inspector As Inspector) Dim cb As CommandBar Dim mnu As ... ByVal lpOperation As String, _ ...
    (microsoft.public.de.outlook)
  • Re: KONTAKTE - KARTE ZUR ADRESSE ANZEIGEN
    ... Karten und Routenplanung direkt aus Outlook aufrufen, ... Wenn Sie einen Kontakt in Outlook anlegen, geben Sie neben dem Namen, der ... ByVal Inspector As Inspector) Dim cb As CommandBar Dim mnu As ... ByVal lpOperation As String, _ ...
    (microsoft.public.de.outlook)
  • Re: HTML Item properties vs. Regular item properties
    ... Why would Outlook record different times for the HTTP ... and the default folder? ... Dim app As Outlook.Application ... "Dmitry Streblechenko" wrote: ...
    (microsoft.public.outlook.program_vba)
  • Re: VBA shutdown error Outlook
    ... In Outlook VBA there is an intrinsic Application object. ... Dim oExpl As Outlook Explorer ... > Public myFlag As Boolean ... > Exit Sub ...
    (microsoft.public.office.developer.outlook.vba)
  • RE: How to copy the format in word document to Outlook Mail
    ... This is where I'm afraid you'll have to do your homework Sangeeta. ... Eric Legault (Outlook MVP, MCDBA, MCTS: ... Dim objOutlook As Outlook.Application ... Dim objWordDoc As Word.Document ...
    (microsoft.public.outlook.program_vba)

Loading