Hide/Show Text Form View

S

Skrewdriver1979

This place has been amazing for help. So I am on to my next challenge.
Basically in a locked form view, an agent selects whether it is an eligible
claim, customer and/or product in check boxes. My goal is to make it look
like this:

ELIGIBLE CLAIM: Yes (CheckBox) No (CheckBox) Show/Hide
ELIGIBLE CUSTOMER: Yes (CheckBox) No (CheckBox) Show/Hide
ELIGIBLE PRODUCT: Yes (CheckBox) No (CheckBox) Show/Hide

Is there a way to show/hide information, such as stipulations to clarify why
they are or are not by clicking a 'show/hide' of sorts in a locked form?

ELIGIBLE CLAIM: Yes (CheckBox) No (CheckBox) Show/Hide
Claims must be based on an alleged defect in the material or workmanship
that is covered by the Limited Warranty.
ELIGIBLE CUSTOMER: Yes (CheckBox) No (CheckBox) Show/Hide
ELIGIBLE PRODUCT: Yes (CheckBox) No (CheckBox) Show/Hide

The eligibility is quite lengthy which is why I want to show/hide the
information. (the examples are just examples). The real catch is, the
eligiblity information varies location to location. I have a drop down to
select location which macro adds the eligibility information with a formfield
when the string is longer then 256 characters.

ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Does any of this make sence? Or even possible in a locked form?
 
G

Graham Mayor

You could run a macro on exit from the checkbox field (here Check1) to write
the required text to a bookmark location (here Check1Result) in the document
eg

Sub Checked1()
Dim oFld As FormFields
Dim rText As Range
Dim bProtected As Boolean
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Set oFld = ActiveDocument.FormFields
Set rText = ActiveDocument.Bookmarks("Check1Result").Range

If oFld("Check1").CheckBox.Value = True Then
rText.Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
" & _
"sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam
" & _
"erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
" & _
"ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
" & _
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam " &
_
"nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat." _
& vbCr & _
"Ut wisi enim ad minim veniam, quis nostrud exerci tation " & _
"ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
" & _
"Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse "
& _
"molestie consequat, vel illum dolore eu feugiat nulla facilisis at " &
_
"vero eros et accumsan et iusto odio dignissim qui blandit praesent " &
_
"luptatum zzril delenit augue duis dolore te feugait nulla facilisi. " &
_
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam " &
_
"nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat."
Else
rText.Text = "This is the text to use when the box is un-checked"
End If

With ActiveDocument
.Bookmarks.Add "Check1Result", rText
.Fields.Update
End With

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

If you want to show or hide the text and retain the space it occupied then
instead of inserting a zero length text string you can format the text
string as white colour which will make it 'invisible'. e.g.

Sub Checked1A()
Dim oFld As FormFields
Dim rText As Range
Dim sText As String
Dim bProtected As Boolean

sText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, " & _
"sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam
" & _
"erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
" & _
"ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
" & _
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam " &
_
"nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat." _
& vbCr & _
"Ut wisi enim ad minim veniam, quis nostrud exerci tation " & _
"ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
" & _
"Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse "
& _
"molestie consequat, vel illum dolore eu feugiat nulla facilisis at " &
_
"vero eros et accumsan et iusto odio dignissim qui blandit praesent " &
_
"luptatum zzril delenit augue duis dolore te feugait nulla facilisi. " &
_
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam " &
_
"nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat."

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Set oFld = ActiveDocument.FormFields
Set rText = ActiveDocument.Bookmarks("Check1Result").Range
rText.Text = sText

If oFld("Check1").CheckBox.Value = True Then
rText.Font.Color = wdColorBlack
Else
rText.Font.Color = wdColorWhite
End If

With ActiveDocument
.Bookmarks.Add "Check1Result", rText
.Fields.Update
End With

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

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Skrewdriver1979

I was having trouble with this. Kept getting an error to do with missing a
bookmark. However, from what I was able to get to work I think that I am
looking for something a little different. Where a macro on exit from check1
will show/hide a (Text Form Field) Text1 while the doc is locked.
 

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