none
How can I create checkboxes using VBA in a Microsoft Word form? RRS feed

  • Question

  • On my form I have the following basic setup and the code below.

    • Entity Name
    • a subform (continuous form) that list the owners of the entity.

    Now the user wants me to include three check boxes after the entity name. Initally the form only includes one place for a single entity but the code below will loop through a create additional entities and owners as needed. This works fine. I am not sure how to create the three checkboxes on the fly if there is more than one entity.

    The code I have is below:

    Set rst = CurrentDb.OpenRecordset("select * from Section2_9") firstRecord = True Do While Not rst.EOF If firstRecord Then wrdDoc.FormFields("NameOfEntity1").Result = IIf(IsNull(rst("BusinessEntityName").Value), "", rst("BusinessEntityName").Value) wrdDoc.Bookmarks("Table2_9").Select firstRecord = False Else wrdDoc.Application.Selection.MoveDown wrdDoc.Application.Selection.TypeParagraph wrdDoc.Application.Selection.TypeParagraph wrdDoc.Application.Selection.TypeText Text:="Name of Entity: " & IIf(IsNull(rst("BusinessEntityName").Value), "", rst ("BusinessEntityName").Value) wrdDoc.Application.Selection.TypeParagraph

    Checkbox code here

    wrdDoc.Tables.Add Range:=wrdDoc.Application.Selection.Range, NumRows:=1, NumColumns:=7, AutoFitBehavior:=0 With wrdDoc.Application.Selection.Tables(1) If .Style <> "Table Grid" Then .Style = "Table Grid" End If .ApplyStyleHeadingRows = True .ApplyStyleLastRow = False .ApplyStyleFirstColumn = True .ApplyStyleLastColumn = False End With With wrdDoc.Application.Selection .SelectRow .ParagraphFormat.Alignment = wdAlignParagraphCenter .Cells.VerticalAlignment = wdCellAlignVerticalBottom .TypeText Text:="Name" .MoveRight Unit:=wdCell .TypeText Text:="Address" .MoveRight Unit:=wdCell .TypeText Text:="Title or Position" .MoveRight Unit:=wdCell .TypeText Text:="O&C Relationship to Applicant or Other Entity" .MoveRight Unit:=wdCell .TypeText Text:="SSN or FEIN" .MoveRight Unit:=wdCell .TypeText Text:="Percent Ownership" .MoveRight Unit:=wdCell .TypeText Text:="Beginning Date" End With End If Set rst2 = CurrentDb.OpenRecordset("select * from Section2_9_Entities WHERE BusinessEntityID = " & rst("ID").Value) Do While Not rst2.EOF wrdDoc.Application.Selection.InsertRowsBelow 1 wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBEName").Value), "", rst2("OCBEName").Value) wrdDoc.Application.Selection.MoveRight Unit:=wdCell wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBEAddress").Value), "", rst2("OCBEAddress").Value) wrdDoc.Application.Selection.MoveRight Unit:=wdCell wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBETitleOrPosition").Value), "", rst2("OCBETitleOrPosition").Value) wrdDoc.Application.Selection.MoveRight Unit:=wdCell wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBERelationshipToApplicantOrOtherEntity").Value), "", rst2 ("OCBERelationshipToApplicantOrOtherEntity").Value) wrdDoc.Application.Selection.MoveRight Unit:=wdCell wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBESSNFEIN").Value), "", rst2("OCBESSNFEIN").Value) wrdDoc.Application.Selection.MoveRight Unit:=wdCell wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBEPercentOwnership").Value), "", Str(rst2("OCBEPercentOwnership").Value)) wrdDoc.Application.Selection.MoveRight Unit:=wdCell wrdDoc.Application.Selection.TypeText Text:=IIf(IsNull(rst2("OCBEBeginningDate").Value), "", Str(rst2("OCBEBeginningDate").Value)) rst2.MoveNext Loop rst2.Close rst.MoveNext Loop rst.Close



    jim neal

    Saturday, February 16, 2013 1:56 AM

Answers

  • Hi Jim

    In that case, go to Word's Insert tab/menu and choose the Symbol button ("More symbols" if this is 2007 or later). You'll find empty and checked boxes in Wingdings and perhaps some other fonts.

    Record macros that insert the two symbols you choose and use that syntax in your code. Just insert the symbol for an empty checkbox where the value is 0/false in your database and the one for a checked box in the opposite case.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 18, 2013 11:19 AM
    Moderator

All replies

  • Hi Jim

    Do these checkboxes need to be "clickable" or just printable?


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, February 16, 2013 8:03 AM
    Moderator
  • The user will check it on the Access form and this will be transferred to the the word form when generated.


    jim neal

    Saturday, February 16, 2013 7:41 PM
  • Hi Jim

    But you aren't answering my question: should the user be able to check (change the state) of the checkbox on the Word document?


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, February 17, 2013 6:49 AM
    Moderator
  • sorry - no, the user can not change the state on the word document

    jim neal

    Monday, February 18, 2013 1:17 AM
  • Hi Jim

    In that case, go to Word's Insert tab/menu and choose the Symbol button ("More symbols" if this is 2007 or later). You'll find empty and checked boxes in Wingdings and perhaps some other fonts.

    Record macros that insert the two symbols you choose and use that syntax in your code. Just insert the symbol for an empty checkbox where the value is 0/false in your database and the one for a checked box in the opposite case.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 18, 2013 11:19 AM
    Moderator
  • Thank you Cindy!!

    jim neal

    Thursday, February 21, 2013 1:18 PM