Checkbox to Unhide Text

J

JohnatSydney

Hi Folks - real beginner here with VBA in word, surrounded by technophobes!

Am trying to do a protected form letter. Users enter details in form fields
which populate through the letter using Cross references. There is one
paragraph that I need to insert/remove based on the user checking a checkbox.
(Checked = include the text, unchecked = exclude). My code is below, but I
get a 'Runtime Error 5941 - The requested member of the collection does not
exist.'

I know this is something simple I've done by not structuring the code
correctly...but can't seem to fix it.

Can anyone offer any advice?
- QualityCheck is the Formfield(Checkbox) Name
- QualityWords is the bookbark containing the hidden text.

If the document is password protected, so I need to unprotect to unhide the
text and re-protect again after it's run?

Sub UnhideQualityText()
Dim QualityCheck As String
If FormFields(QualityCheck).CheckBox.Value = False Then
ActiveDocument.Bookmarks("QualityWords").Range.Font.Hidden = True
Else
ActiveDocument.Bookmarks("QualityWords").Range.Font.Hidden = False
End If
End Sub

Appreciate any advice.....
Thanks,
John.
 
J

Jezebel

The mistake in your code is that you declare the string variable
QualityCheck but don't assign it a value. So the line
FormFields(QualityCheck) is effectively FormFields("")

Try --

ActiveDocument.Bookmarks("QualityWords").Range.Font.Hidden = not
FormFields("QualityCheck").CheckBox.Value
 

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