Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Activate form field if another checkbox is checked

    Is there a way to activate/make visible/go to a text form field if a checkbox is marked?
    I am designing a survey, and if the Strongly Agree/Disagree checkboxes are marked, I want the user to be prompted to enter a comment.

    I've tinkered with the FILLIN field (always comes up) & read about the ASK & SET fields - they seem based on Mail merge.
    Willing to try VBA - but will need hand holding.

    THANKS!
    Tracey Morris

  2. #2
    Star Lounger
    Join Date
    Apr 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activate form field if another checkbox is checked

    Yes, you can set up the form to go to a Comment text box only if the checkbox is set to true.

    I'm assuming (yes, I know what assuming does!) the checkbox is a form field check box. The checkbox name/bookmark for this example is chkTest. The after exit property is set to run the macro you define below.

    The comment text box's name/bookmark is set up as txtComment.

    Define a macro and paste in the following code (some of this is written in WordBasic as I'm borrowing from a form I wrote for Word '95 - however it still works in Word '97).

    That should do the trick for you. Best of luck!

    ==== Paste in code found below this line ====

    Dim ysnchkTest$

    ysnchkTest$ = WordBasic.[GetFormResult$]("chkTest")

    If ysnchkTest$ = 1 Then
    WordBasic.WW7_EditGoTo "txtComment"
    End If

    [img]/w3timages/icons/woof.gif[/img][img]/w3timages/icons/woof.gif[/img]

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activate form field if another checkbox is checked

    Tracey,

    You might try something like this:

    Give the first checkbox the name "check1", and the second "check2"

    Enter this macro:
    <pre>sub CheckValue1
    Dim blnProtected As Boolean
    blnProtected = False
    ' Check if it's already protected (usefule for testing)
    If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
    blnProtected = True
    ActiveDocument.Unprotect
    End If
    If ActiveDocument.FormFields("check1").Result = 0 Then
    ' If the first check box is not filled in, disable the second check box
    ActiveDocument.FormFields("check2").Enabled = False
    Else
    ActiveDocument.FormFields("check2").Enabled = False
    End If

    If blnProtected Then
    ' Reprotect if it was previously- the "noreset" makes sure fields are not zapped
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
    End If
    end sub
    </pre>


    then make this macro run after you exit from "check1"- double click on check1, and make the "macro on exit" macro "CheckValue1"

    If you've never done it before, it's complex. Give it a try first, and come back for answers when you're stuck (as I'm sure you will!)
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •