Toggle Between Two Values in Protected Form

J

Jason Roberts

I beleive what I want to do is relatively easy, but I'm still learning VBA
and am too tired to think at this point.

I have a protected form. On this form, I want a field called "revised." It
should toggle between two values: "REVISED" and "" (i.e. nothing).

Originally, I wanted to use a FORMCHECKBOX field in conjunction with an IF
field. The plan was to allow the user to check the checkbox if the form was
revised, and the IF field would look at that whether the box was checked.
Something like: { IF revised = true "REVISED" "" } No matter how I did it,
though, it did not work. I have since read somewhere that you can't use the
value of a FORMCHECKBOX in an IF field. (I'm using Word 2003 if it matters.)

So now I'm looking at a MACROBUTTON. What I want is a button that will
toggle the value of the "revised" field between "REVISED" and "". Like I
said, I think this should be an easy task, but my brain is fried at this
point. I figure one of you MVPs will be able to whip this out in your sleep.

Thanks,

-J.
 
D

Doug Robbins

Use a macro that runs on exit from the checkbox field and sets the .Result
of an accompanying textbox to the appropriate value

With ActiveDocument
If .Formfields("RevisedCheckBox").CheckBox.Value = True Then
.Formfields("RevisedTextBox").Result = "Revised"
Else
.Formfields("RevisedTextBox").Result = ""
End If
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jason Roberts

Doug-

Thanks for the help with the checkbox solution. The more I think about it,
the more I think I'd rather use a macrobutton, for two reasons: First, a
checkbox is going to be inserted into the tab order on my form; second, I
already have macrobuttons for other functions, so it's consistent for the
user.

So, anyone have any ideas on the macrobutton scenario?

-J.
 
G

Greg

Jason,

You could build a custom documentproperty and name is say "State"

Use a field like {MacroButton Toggle { DocProperty "State"}}

Then a macro something like:

Sub Toggle()
Dim oProp As DocumentProperty
Set oProp = ActiveDocument.CustomDocumentProperties("State")
If oProp.Value = "Original" Then
oProp.Value = "Revised"
Else
oProp.Value = "Original"
End If
Selection.Fields(1).Update
End Sub

The problem is I used "Original" where you wanted "". The problem with
"" is that there will be nothing displayed in the Macrobotton field for
the user to see and double click.

Best I can offer.
 
J

Jason Roberts

Resolved...

I modified Doug's macro and used it with a macrobutton. Where I had asked
for the resulting field to be either "REVISED" or blank, I changed that to be
either "REVISED PROPOSAL" or "PROPOSAL." ("PROPOSAL" was originally to be in
the protected part of the form, but I could find no way to keep a blank field
from showing and moving the text that follows it. Not that it matters at this
point, but is there a way to keep a field from showing the standard empty
field if there is no value?)

The field "RevisedText" defaults to a value of "PROPOSAL." The macrobutton
then executes the following.

With ActiveDocument
If .FormFields("RevisedText").Result = "PROPOSAL" Then
.FormFields("RevisedText").Result = "REVISED PRPOPOSAL"
Else
.FormFields("RevisedText").Result = "PROPOSAL"
End If
End With

I kinda feel stupid for thinking it would be more complicated.

Thanks for your help, guys.

-J.
 
D

Doug Robbins

You could insert a DocVariable { DOCVARIABLE varRevisedText }field in the
document in place of the Text formfield and the use the following code:

With ActiveDocument
If .Variables("varRevisedText").Value = "PROPOSAL" Then
.Variables("varRevisedText").Value= "REVISED PROPOSAL"
Else
.Variables("varRevisedText").Value = "PROPOSAL"
End If
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jason Roberts

Thanks, Doug!

I was playing around with DOCVARIABLEs on my own, but was doing something
wrong. I just didn't like the grey highlight around the changing text. Your
code worked perfectly, after I created the variable elsewhere. That was
exactly what I needed.

Again, thanks.

-J.
 

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