How do you add an IF statement to a user form field?

L

Larry Root

I want to create a simple form to enter answers to 20 or so questions. How
do I lock a field (so the user cannot manually return and enter a value) if
the previous entry was "no" and then jump to the next series of questions
For example:

-----
Have you talked to accounting? [TalkedToAccounting] (drop down box --
yes/no)

IIF TalkedToAccounting = yes
THEN go to [AccountantsName]
ELSE lock [AccountantsName]
lock [AccountantsAnswer]
go to [LegalQuestions]
END IF

If so, which Accountant did you talk to? [AccountantsName]
What did the Account tell you? [AccountantsAnswer]
.. . .
[LegalQuestions]

-----


I'd sincerely appreciate any suggestions on how I could implement that logic
within form fields.


Very respectfully,
Larry

I"d like to lock the
 
G

Graham Mayor

This could be tricky to implement and will rely on ensuring that users will
allow macros to run and that users tab out of the field. In which case run
the following macro on exit from the dropdown field

Dim sPassword As String
sPassword = "" 'password to protect/unprotect form
With ActiveDocument
.Unprotect Password:=sPassword
If LCase(.FormFields("TalkedToAccounting").Result) = "yes" Then
.FormFields("AccountantsName").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = True
.Execute
End With
.FormFields("AccountantsAnswer").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = True
.Execute
End With
.FormFields("AccountantsName").Select
Else
.FormFields("AccountantsName").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = False
.Execute
End With
.FormFields("AccountantsAnswer").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = False
.Execute
End With
.FormFields("LegalQuestions").Select
End If
.Protect NoReset:=True, Password:=sPassword, _
Type:=wdAllowOnlyFormFields
End With

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

Larry Root

Graham,

Thank you very much for your solution.

Unfortunately, I'm working with very well educated individuals who all want
to do it their way; we end up iterating several times through the questions
because they won't "waste time" on such mundane tasks as reading a single
sentence of directions. So I'm afraid that I cannot assume that they'll
either follow directions to tab out of the field or wait for the macro to
complete, which is why I'm trying to restrict their discretion.

Rather than a simple, single sheet form, I'll look into using different form
modules and sequence the modules with logic to expose them to only what they
need to do next.

VERY respectfully,
Larry



Graham Mayor said:
This could be tricky to implement and will rely on ensuring that users will
allow macros to run and that users tab out of the field. In which case run
the following macro on exit from the dropdown field

Dim sPassword As String
sPassword = "" 'password to protect/unprotect form
With ActiveDocument
.Unprotect Password:=sPassword
If LCase(.FormFields("TalkedToAccounting").Result) = "yes" Then
.FormFields("AccountantsName").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = True
.Execute
End With
.FormFields("AccountantsAnswer").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = True
.Execute
End With
.FormFields("AccountantsName").Select
Else
.FormFields("AccountantsName").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = False
.Execute
End With
.FormFields("AccountantsAnswer").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = False
.Execute
End With
.FormFields("LegalQuestions").Select
End If
.Protect NoReset:=True, Password:=sPassword, _
Type:=wdAllowOnlyFormFields
End With

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Larry said:
I want to create a simple form to enter answers to 20 or so
questions. How do I lock a field (so the user cannot manually return
and enter a value) if the previous entry was "no" and then jump to
the next series of questions For example:

-----
Have you talked to accounting? [TalkedToAccounting] (drop down box --
yes/no)

IIF TalkedToAccounting = yes
THEN go to [AccountantsName]
ELSE lock [AccountantsName]
lock [AccountantsAnswer]
go to [LegalQuestions]
END IF

If so, which Accountant did you talk to? [AccountantsName]
What did the Account tell you? [AccountantsAnswer]
. . .
[LegalQuestions]

-----


I'd sincerely appreciate any suggestions on how I could implement
that logic within form fields.


Very respectfully,
Larry

I"d like to lock the
 
G

Graham Mayor

You can overcome the tabbing issue by validating the form fields - see
http://www.gmayor.com/formfieldmacros.htm
and there are some examples on my web site
http://www.gmayor.com/word_vba_examples.htm which show how to insert
sections of forms as required by the data filled so far. Education however
is no substitute for common sense :)

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Larry said:
Graham,

Thank you very much for your solution.

Unfortunately, I'm working with very well educated individuals who
all want to do it their way; we end up iterating several times
through the questions because they won't "waste time" on such mundane
tasks as reading a single sentence of directions. So I'm afraid that
I cannot assume that they'll either follow directions to tab out of
the field or wait for the macro to complete, which is why I'm trying
to restrict their discretion.

Rather than a simple, single sheet form, I'll look into using
different form modules and sequence the modules with logic to expose
them to only what they need to do next.

VERY respectfully,
Larry



Graham Mayor said:
This could be tricky to implement and will rely on ensuring that
users will allow macros to run and that users tab out of the field.
In which case run the following macro on exit from the dropdown field

Dim sPassword As String
sPassword = "" 'password to protect/unprotect form
With ActiveDocument
.Unprotect Password:=sPassword
If LCase(.FormFields("TalkedToAccounting").Result) = "yes" Then
.FormFields("AccountantsName").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = True
.Execute
End With
.FormFields("AccountantsAnswer").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = True
.Execute
End With
.FormFields("AccountantsName").Select
Else
.FormFields("AccountantsName").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = False
.Execute
End With
.FormFields("AccountantsAnswer").Select
With Dialogs(wdDialogFormFieldOptions)
.Enable = False
.Execute
End With
.FormFields("LegalQuestions").Select
End If
.Protect NoReset:=True, Password:=sPassword, _
Type:=wdAllowOnlyFormFields
End With

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Larry said:
I want to create a simple form to enter answers to 20 or so
questions. How do I lock a field (so the user cannot manually
return and enter a value) if the previous entry was "no" and then
jump to the next series of questions For example:

-----
Have you talked to accounting? [TalkedToAccounting] (drop down box
-- yes/no)

IIF TalkedToAccounting = yes
THEN go to [AccountantsName]
ELSE lock [AccountantsName]
lock [AccountantsAnswer]
go to [LegalQuestions]
END IF

If so, which Accountant did you talk to? [AccountantsName]
What did the Account tell you? [AccountantsAnswer]
. . .
[LegalQuestions]

-----


I'd sincerely appreciate any suggestions on how I could implement
that logic within form fields.


Very respectfully,
Larry

I"d like to lock the
 

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