+ Reply to Thread
Results 1 to 18 of 18

Form Design in Word

  1. #1
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Form Design in Word

    Hi,

    I need to create a form in Word 2003 that will be used to gather data. However, I need to build the following functionality into the form:

    1. Checkboxes – only allow a user to tick one Checkbox in a group (I think I got this one sorted)
    2. Mandatory Fields - need certain fields to always be populated
    3. If a Checkbox is ticked, need to set a default value in a Text Field.
    4. Make a selection of fields in an area of the form mandatory if a checkbox is selected.
    5. Hide certain fields if a checkbox is ticked

    I have done some playing around with the Forms toolbar and so far, only got No. 1 above working. The rest I cant seem to make any headway on.

    I've attached a sample form containing the kinds of things I'd like to be able to do.

    Can anyone help?

    Many Thanks in Advance...
    Attached Files Attached Files

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    For code re mandatory fields, see: http://www.excelforum.com/word-progr...ed-fields.html

    Do note that it is not possible to hide formfields of any kind. Accordingly, you would need to add/delete the formfields programatically, for which see: http://www.msofficeforums.com/word/1...html#post30792
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    07-19-2012
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Form Design in Word

    Quote Originally Posted by macropod View Post
    For code re mandatory fields, see: http://www.excelforum.com/word-progr...ed-fields.html

    Do note that it is not possible to hide formfields of any kind. Accordingly, you would need to add/delete the formfields programatically, for which see: http://www.msofficeforums.com/word/1...html#post30792
    Thanks for share valuable information.......

  4. #4
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Paul,

    Thank you so much, those links are a great help.


  5. #5
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Paul,

    A couple of additional questions...

    As a follow-on from the query you answered above RE programatically, is it only possible to do this on a field by field basis, i.e. could you have a set of fields stored in an AutoText entry or something and then have VBA insert this AutoText entry if a checkbox field is selected? Its just that I may have 20-30 fields that need to be hidden or displayed which would mean a lot of code.

    And as a follow-on from mandatory fields. The sample above is great but the form I'm designing can have varying mandatory fields, depending on selections made along the way. So if tick checkbox A, I might want to make TextField 1, TextField5 and TextField8 mandatory whereas if I tick Checkbox B, I may want TextField2,TextField3 and TextField11 to be mandatory. Is this in any way possible?

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    Adding fields could not be done via an Autotext entry. The only practical workaround I can think of for Office 2003 would be to have another document with all the fields in-situ and copy those into the current document on demand.

    As for the second question, yes, that's possible. What would be required is the addition of a series of IF tests (or perhaps Select Case tests) to determine when a particular field is mandatory.

  7. #7
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    I’ve started working on the form and so far am getting on ok. I’ve been able to use code to hide/show bookmarked areas which contain the fields required based on other selections. I’ve also used code to enable/disable particular fields based on other selections made.

    There is one thing I just can’t seem to figure out. Paul, you alluded to it in your last post but I’m unsure of how I would do it. I basically need certain fields to be made mandatory based on selections made in other fields. I would like if say, I choose ‘A’ in a dropdown field, that 4 other fields will automatically become mandatory and must be filled in before the form can be saved. So depending on whatever selections are made by the user, the mandatory fields will vary each time a user populates the form. So the code provided earlier works, but only when the mandatory fields are fixed. How could I amend it to cater for varying mandatory fields, or am I asking too much? Or is there another approach I could use?

    Thanks again in advance…

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    Hi Lyla,

    basically, it's a matter of having a series of If tests or a Select Case statements to determine which fields get added to the 'required' collection when the document is saved. So, for example, if a particular dropdown has 'Yes' selected, you might have one group of formfields added to the collection but, if it's 'no', another set might be added. And so on for other 'trigger' formfields.

  9. #9
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Thanks for your quick reply! I can understand the logic of what you are suggesting. Its my limited coding abilities that are the problem! I understand I can use the IF to test what value a field contains but could you give me a start on what code would add the desired fields to the required collection?

    So to test the dropdown field, I know I would start with this:

    If ActiveDocument.FormFields("DropDownX").DropDown.Value = 1 Then

    ???????
    Last edited by Cutter; 08-23-2012 at 01:32 PM. Reason: Removed whole post quote

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    Hi Lyla,

    Yes, it'd be something like:
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Ah! So I can just code the IF statements into the BeforeSave code. So obvious when you think about it but I had totally overcomplicated it in my head! So my code might look something like:

    Please Login or Register  to view this content.

    I will try this and see how I get on.

    Thank you so much, am learning a lot!!

  12. #12
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    For consistency with the rest of the code you're using, you'd need to change 'ActiveDocument' to 'Doc', but that's about it.

  13. #13
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Me Again!

    I've had to revise my approach on the validation of the mandatory fields. When this form is filled, it will be populated by a few different users meaning it may be saved many times before all the required fields are filled by the different users. So the checking of the mandatory fields on the Save action is useless in this case.

    As an alternative, there is a field at the end of the form that must be filled which is a vital field that cannot be left blank. So could I assign an 'On Entry' macro to this field that would check that all mandatory fields have been filled before it will permit the user to fill in this vital field? I tried to implement the code above and use it in this context but its giving a Runtime error 424 - Object Required error and highlighting the line ReqFields.Add Doc.FormFields("ReasonChange") as the problem.

    Here's the code I'm assigning as the On Entry macro for the field:

    Please Login or Register  to view this content.
    I'd really appreciate your guidance on this...

    Thanks

  14. #14
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    Hi lyla,

    A simpler approach would be to test whether the last formfield has been filled in at the time of saving. If not, just exit normally. You could do with with:
    Please Login or Register  to view this content.
    where 'LastField' is the bookmark name assigned to the "field at the end of the form that must be filled which is a vital field that cannot be left blank"
    Last edited by macropod; 09-05-2012 at 08:47 PM.

  15. #15
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Perfect, Thanks so much Paul! That should work great!

  16. #16
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    My form is still in development and I’m having trouble with the latest requirement. Paul, you have been so helpful thus far, I’m hoping you may have a way for me to do the following.

    I have successfully implemented the code in earlier posts which checks if various mandatory fields have been populated at the point of Saving and it works well. The only issue has been the vast amounts of criteria I’ve had to code (LOTS of IF Statements!). But it’s working.

    I now have a new table to be added to the form. I have a macro which sets the correct colour on the fields in the first row (Yellow = mandatory, Green = Optional) and then I have a macro to automatically give the user a new row if required and create form fields on the fly based on the previous row’s fields. Because I can’t foresee how many rows will be used, I can’t set fixed mandatory fields.

    So could I code into the DocumentBeforeSave module something that would check in the table for any field that has a yellow background and set it as a mandatory field? Or maybe the field contents of certain columns in the table could be flagged as mandatory?

    I’ve attached a sample document containing a similar table to what I’ll be using.

    Any help would be greatly appreciated.
    Attached Files Attached Files

  17. #17
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Form Design in Word

    Given that the fields are in a regular table, you could simply test all cells in the specified columns for completion. That way you don't need to know anything about the field names, colours, etc.

    The following function returns a string containing outstanding cell references:
    Please Login or Register  to view this content.
    You call the function by passing it a table number and a series of columns to test (eg TableTest(1, "1,2,4") to test columns 1, 2 & 4 of table 1).

    Here's an example of how you might use it:
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    05-24-2012
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 365
    Posts
    149

    Re: Form Design in Word

    Brilliant as always!

    I think that should work perfectly.

    Thank you SO much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1