Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Larry Root Larry Root is offline
external usenet poster
 
Posts: 11
Default How do you add an IF statement to a user form field?

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
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How do you add an IF statement to a user form field?

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
Word MVP web site http://word.mvps.org



Larry Root wrote:
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



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Larry Root Larry Root is offline
external usenet poster
 
Posts: 11
Default How do you add an IF statement to a user form field?


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" wrote:

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
Word MVP web site http://word.mvps.org



Larry Root wrote:
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




  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How do you add an IF statement to a user form field?

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
Word MVP web site http://word.mvps.org



Larry Root wrote:
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" wrote:

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
Word MVP web site http://word.mvps.org



Larry Root wrote:
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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form field in conditional statement [email protected] Microsoft Word Help 4 April 28th 09 06:17 AM
Form Date Field- Does user have to type separators? Mary Microsoft Word Help 3 February 8th 09 06:35 AM
How can a user change the default date in a form field? I_AM_SAM Tables 1 June 22nd 05 10:20 PM
Adding Autotext in a Macro User Form field Onka Microsoft Word Help 1 February 10th 05 05:39 AM
allow user to add text to an already existing form list field CK@PPC Microsoft Word Help 2 February 3rd 05 09:44 AM


All times are GMT +1. The time now is 10:09 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"