Forms VBA Help

J

Jesse

I have a word form that contains two checkboxes (yes and
no) and a third field that requires user input into a text
field if the "No" checkbox is marked. I am using the
following macro that allows the user to mark either Yes or
No only and named the fields PentiumA and PentiumB
respectively:

Set vPentiumA = ActiveDocument.FormFields
("PentiumA").CheckBox
Set vPentiumB = ActiveDocument.FormFields
("PentiumB").CheckBox

If vPentiumA.Value = True Then
vPentiumB.Value = False

End If
End Sub

I want to add a statement to this macro that will prevent
the user from adding text to the text field (named
PentiumC) when the checkbox is marked Yes.

Being relatively new to macros I can't figure out the code
required to get there. Can anyone help?

Thanks
 
J

Jay Freedman

Hi, Jesse,

The property you need is the .Enabled property of the text form field
(PentiumC). Use something like this as the exit macro of check box PentiumA:

Sub PentiumAExit()
Dim vPentiumA As FormField, vPentiumC As FormField
Set vPentiumA = ActiveDocument.FormFields("PentiumA")
Set vPentiumC = ActiveDocument.FormFields("PentiumC")

If vPentiumA.CheckBox.Value Then
vPentiumC.Enabled = True
vPentiumC.Range.Select
Else
vPentiumC.Enabled = False
End If
End Sub

When vPentiumC.Enabled = False, it's impossible to put the cursor in that
field. You may also want to add vPentiumC.Result = "" to clear the field.

Also, look again at your design -- if you use the right words in the caption
of PentiumA, you probably don't need PentiumB at all. Just try to make it
clear that when PentiumA is checked that means "yes", and when it's
unchecked that means "no".
 

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