When a check box is checked a text box field will pop up automatic

V

Victoria

Is there a way to have a text box field pop up when a check box is checked?

Example:

1. Please check the boxes that you would like to work on:

[check box] - Nursery
[check box] - Welcome Center
[check box] - Hospitality

Say the Nursery box is checked, is there a way to have something like this
pop up automatically:

Nursery - [text field]

So for example: the "text field" will be where the person would enter their
availability
 
G

Graham Mayor

It's a bit complicated and requires vba, however assuming 'Nursery' is a
checkbox 'Check1' and you have a bookmark placed where you want the field to
appear named 'Nursery'. The following macro run on exit from Check1 will
enter or remove a form field 'Nur1' according to the setting of Check1.
http://www.gmayor.com/installing_macro.htm

You will need similar macros with different bookmarks for each check box
that you wish to be associated with such a pop up field.


Sub ExitCHK1()
Dim bProtected As Boolean
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Check whether Checkbox1 is checked
If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
'Trap the non-existence of field "Nur1"
On Error GoTo AddField:
'Check if there is a field already place and if so delete it
With Selection
.GoTo What:=wdGoToBookmark, Name:="Nur1"
.Delete Unit:=wdCharacter, Count:=1
End With
AddField: 'Locate the field position bookmark and add a form field "Nur1"
With Selection
.GoTo What:=wdGoToBookmark, Name:="Nursery"
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.PreviousField.Select
End With
Selection.FormFields(1).Name = "Nur1"
GoTo Finished:

Else 'Checkbox is unchecked
On Error GoTo CleanUp: 'There is no field so finish and reprotect the form
'Remove the form field if it exists
With Selection
.GoTo What:=wdGoToBookmark, Name:="Nur1"
.Delete Unit:=wdCharacter, Count:=1
End With
End If
CleanUp:
'Goto the next field - here check box 2
Selection.GoTo What:=wdGoToBookmark, Name:="Check2"
'Reprotect the document.
Finished:
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
V

Victoria

So will I need to change the verbiage on the macro you gave me below for each
pop-up?

Meaning, everywhere you have NUR1, I need to change this to a new name per
checkbox?


Graham Mayor said:
It's a bit complicated and requires vba, however assuming 'Nursery' is a
checkbox 'Check1' and you have a bookmark placed where you want the field to
appear named 'Nursery'. The following macro run on exit from Check1 will
enter or remove a form field 'Nur1' according to the setting of Check1.
http://www.gmayor.com/installing_macro.htm

You will need similar macros with different bookmarks for each check box
that you wish to be associated with such a pop up field.


Sub ExitCHK1()
Dim bProtected As Boolean
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Check whether Checkbox1 is checked
If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
'Trap the non-existence of field "Nur1"
On Error GoTo AddField:
'Check if there is a field already place and if so delete it
With Selection
.GoTo What:=wdGoToBookmark, Name:="Nur1"
.Delete Unit:=wdCharacter, Count:=1
End With
AddField: 'Locate the field position bookmark and add a form field "Nur1"
With Selection
.GoTo What:=wdGoToBookmark, Name:="Nursery"
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
.PreviousField.Select
End With
Selection.FormFields(1).Name = "Nur1"
GoTo Finished:

Else 'Checkbox is unchecked
On Error GoTo CleanUp: 'There is no field so finish and reprotect the form
'Remove the form field if it exists
With Selection
.GoTo What:=wdGoToBookmark, Name:="Nur1"
.Delete Unit:=wdCharacter, Count:=1
End With
End If
CleanUp:
'Goto the next field - here check box 2
Selection.GoTo What:=wdGoToBookmark, Name:="Check2"
'Reprotect the document.
Finished:
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Is there a way to have a text box field pop up when a check box is
checked?

Example:

1. Please check the boxes that you would like to work on:

[check box] - Nursery
[check box] - Welcome Center
[check box] - Hospitality

Say the Nursery box is checked, is there a way to have something like
this pop up automatically:

Nursery - [text field]

So for example: the "text field" will be where the person would enter
their availability
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top